Skip to content
Advertisement

Spring boot filter is ignored

I m trying to create a filter, but it is ignored

@Component
@Order(1)
public class CarsFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest httpServletRequest,
                                    HttpServletResponse httpServletResponse,
                                    FilterChain filterChain) throws ServletException, IOException {

        httpServletResponse.addHeader("X", "XX");
        filterChain.doFilter(httpServletRequest, httpServletResponse);
    }
}

Did I forget to do smth?

Advertisement

Answer

The problem was in the absent of pom dependency

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Instead the Filter was loaded from some java library and therefor compilation was successful (can be removed in module settings)

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement