Skip to content

@ServletComponentScan does not register servlet components in a mock web environment #39736

@Crain-32

Description

@Crain-32

Affects: 2.7.9 - 3.2.3 (Likely more, I just tested the latest and a random 2.7)

When using @WebFilter with either the value or urlPatterns fields defined, Spring fails to respect them. It would make sense that the following behaves the same.

@Webfilter("/rest/example/*") @Component public static class SimpleFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { filterChain.doFilter(request, response); } } // Should behavior similar to @Webfilter @Component public static class SimpleFilter extends OncePerRequestFilter { @Override protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { return !request.getRequestURI().startsWith("/rest/example"); } @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { filterChain.doFilter(request, response); } }

A repository configured with all three WebFilter variations and tests for them can be found here.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions