When using @Component
+ @WebFilter
, you're actually registering the filter twice with Embedded Tomcat:
@Component
registers it through Spring's component scanning@WebFilter
registers it through servlet container's scanningThis is why using both annotations works, but it's not the recommended approach
but in Traditional Spring MVC (External Tomcat):
@WebFilter
is a standard Jakarta EE annotation that's processed by the servlet container (Tomcat)@Component
is a Spring framework annotationWhen using external Tomcat, the servlet container handles @WebFilter registration directly This is why you get the "already registered" error when using both annotations
=> Working with Just @WebFilter
require using @ServletComponentScan
in the Spring Boot application, This annotation enables scanning for servlet components including @WebFilter