configuration - Servlet Filter as Component Spring Boot - Stack Overflow
1) It works even when I comment out FilterRegistrationBean piece of code. I feel I must use FilterRegistrationBean if I want to set certain order. Correct?
It works because any Filter
beans are automatically registered with some default configuration unless you've provided an explicit registration bean.
2) Is there any way I can set order or other configuration like url patterns without FilterRegistrationBean?
You can set the order by using @Order
on your Filter
or having it implement Ordered
.
You should use a registration bean if you want to set the URL pattern
3) I believe I can use @Component can replace @Configuration annotation on Filter class and it will work correctly?
Correct. Your filter isn't configuration so it should be annotated with @Component
rather than @Configuration
4) And finally Is it good to have Filter class itself marked as @Component/@Configuration?
Yes, it's fine to annotate a Filter with @Component
. The alternative would be to use a @Bean
method on a @Configuration
class.
Read full article from configuration - Servlet Filter as Component Spring Boot - Stack Overflow
No comments:
Post a Comment