问题
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