add a filter with urlMapping on spring boot

夙愿已清 提交于 2020-01-04 01:50:15

问题


I have a class like this

@WebFilter(urlPatterns={"/message/*","/private_message"})
@Component
public class TokenAuthenticationFilter extends FilterRegistrationBean {

and I thought that Spring Boot would respect the urlPatterns setted, but for some reason, every request gets to this filter. I think I may be doing something wrong.
Also, I'm not using Spring Security


回答1:


You're mixing use of @WebFilter and FilterRegistrationBean. The former should be used on a class that is a Filter and in conjunction with @ServletComponentScan. The latter should be published as a bean (as you are doing by annotating with @Component) and the url mappings configured using its setUrlPatterns method.



来源:https://stackoverflow.com/questions/34031170/add-a-filter-with-urlmapping-on-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!