给定这个过滤器:
public class MyFilter implements Filter{
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
System.out.println("FILTERING!!!!!!!!!!!!!!!!!!!"+((HttpServletRequest)request).getRequestURI());
chain.doFilter(request, response);
}
我已经看到在同一个请求中被多次调用
春季启动应用程序:
@SpringBootApplication(scanBasePackageClasses={MySpringBootDemoApplication .class, TilesConfiguration.class})
public class MySpringBootDemoApplication {
public static void main(String[] args) {
SpringApplication.run(MySpringBootDemoApplication .class, args);
}
@Bean
public Filter myFilter(){
return new MyFilter();
}
}
瓷砖配置:
@Configuration
public class TilesConfiguration {
@Bean
public TilesConfigurer tilesConfigurer() {
final TilesConfigurer configurer = new TilesConfigurer();
configurer.setDefinitions(new String[] { "WEB-INF/**/tiles.xml" });
configurer.setCheckRefresh(true);
return configurer;
}
@Bean
public TilesViewResolver tilesViewResolver() {
final TilesViewResolver resolver = new TilesViewResolver();
resolver.setViewClass(TilesView.class);
return resolver;
}
}
这是我在日志中看到的:
FILTERING!!!!!!!!!!!!!!!!!!!/spring-boot-demo/home
FILTERING!!!!!!!!!!!!!!!!!!!/spring-boot-demo/WEB-INF/layouts/standard.jsp
FILTERING!!!!!!!!!!!!!!!!!!!/spring-boot-demo/WEB-INF/layouts/standard.jsp
FILTERING!!!!!!!!!!!!!!!!!!!/spring-boot-demo/WEB-INF/layouts/standard.jsp
浏览器发出的唯一真实请求是:
FILTERING!!!!!!!!!!!!!!!!!!!/spring-boot-demo/home
与 ( ) 相关的图块/standard.jsp
从何而来?在传统的 Spring MVC 应用程序中,它们从未出现过。
我知道 MyFilter 可以扩展 OncePerRequestFilter 但我无法修改我必须使用的真实过滤器,它们来自遗留库。