如何在Spring中记录Web请求和响应?

时间:2012-01-18 20:43:34

标签: java spring logging spring-mvc

我想知道用户使用的网页的哪些部分,然后将其呈现在漂亮的图形界面中。我唯一能想到的就是:

@Controller
public class WebController {

    @Autowired
    private DatabaseResource dbr;

    @RequestMapping("/foobar")
    public String getFoobar(Principal principal, ModelMap model, HttpServletRequest req) {
    dbr.logVisit(req); //write the request to a database
 //...

在每个@RequestMapping中,我将请求写入数据库。这是最好的方法吗?

它是否存在一个库,所以我不必自己编写它?有点像Eclipse Usage Data Collector的包。

我正在使用Spring和Spring Security。

1 个答案:

答案 0 :(得分:1)

编写自定义HandlerInterceptor,此功能专门用于实现此类功能。

另一种方法是使用与Tomcat紧密无缝集成的Logback Access

相关问题