本文介绍了在Spring Boot中为Servlet配置添加过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用spring-boot-starter-web捆绑包构建基于spring-batch-admin的web应用.
I am using the spring-boot-starter-web bundle to build a spring-batch-admin based webapp.
@Configuration @EnableAutoConfiguration(exclude = { BatchAutoConfiguration.class, DataSourceAutoConfiguration.class, WebMvcAutoConfiguration.class }) @Import(MainConfiguration.class) @EnableTransactionManagement public class BatchAdmin extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(BatchAdmin.class, args); } // ... } @Configuration @ComponentScan("company.package*") @Import({ ServletConfiguration.class, WebappConfiguration.class }) public class MainConfiguration {} @Configuration @ImportResource("classpath:/org/springframework/batch/admin/web/resources/servlet-config.xml") public class ServletConfiguration {} @Configuration @ImportResource({ "classpath:/org/springframework/batch/admin/web/resources/webapp-config.xml","classpath:persistence-context.xml" }) public class WebappConfiguration {}如何使用Java配置样式将此过滤器添加到servlet上下文中?
How can I add this filter to the servlet context using the java configuration style?
<filter-mapping> <filter-name>hiddenHttpMethodFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>推荐答案
有时候(但不经常),比起问问SO社区,查阅文档要快得多.
Sometimes (but not often) it's faster to consult the documentation than asking the SO community.
根据官方弹簧启动文档,我必须将以下bean定义添加到BatchAdmin类中.
According to the official spring-boot documentation, I had to add the following bean definition to the BatchAdmin class.
@Bean public Filter hiddenHttpMethodFilter() { HiddenHttpMethodFilter filter = new HiddenHttpMethodFilter(); return filter; }更多推荐
在Spring Boot中为Servlet配置添加过滤器
发布评论