在Spring启动Web应用程序中记录http流量

时间:2015-01-30 16:51:52

标签: spring http logging

我在tomcat7上安装了一个spring boot web应用程序。我正在寻找一种方法来记录http传入和传出请求(标题和正文)。我正在寻找类似于org.apache.cxf.interceptor.LoggingOutInterceptor的东西。 你能帮忙吗?

1 个答案:

答案 0 :(得分:3)

您可以实现自己的过滤器,如:

@Component
public class SimpleFilter implements Filter {

    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) res;
        HttpServletRequest request = (HttpServletRequest) req;
        // logic...
        chain.doFilter(req, res);
    }

    public void init(FilterConfig filterConfig) {}

    public void destroy() {}

}

对于拦截请求和响应的两个要求,这也是一个很好的解决方案......

相关问题