在Spring Boot中为Servlet配置添加过滤器

编程入门 行业动态 更新时间:2024-10-26 10:32:03
本文介绍了在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配置添加过滤器

本文发布于:2023-10-31 19:16:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547028.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过滤器   中为   Spring   Boot   Servlet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!