为SpringBoot应用添加可以配置的拦截器 发表于 2017-07-26 | 阅读次数 1234567891011121314151617@Configuration@ConditionalOnExpression("${cache.response.enabled:false}")public class FilterRegistrationBeanConfigration { @Bean public FilterRegistrationBean filterRegistrationBean() { return new FilterRegistrationBean() {{ setFilter(new OncePerRequestFilter() { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { HttpServletResponse responseToUse = new ContentCachingResponseWrapper(response); filterChain.doFilter(request, responseToUse); ((ContentCachingResponseWrapper) responseToUse).copyBodyToResponse(); } }); }}; }} 1cache.response.enabled=true Donate Alipay 本文作者: Diamond Yuan 本文链接: https://blog.diamondyuan.com/2017/07/26/add-configurable-bean-for-springboot/ 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!