-
Notifications
You must be signed in to change notification settings - Fork 40.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@ServletComponentScan does not register servlet components in a mock web environment #39736
Comments
Thanks for the report but that's the wrong issue tracker. Moving to Spring Boot. From a quick debugging session, those filters are indeed taken into account by |
Mixing Spring's component model and the Servlet spec's component model isn't supported. This means that your sample also doesn't work as you would like when running its main method as the url patterns are ignored there too. If you want to use @ServletComponentScan
@SpringBootApplication
public class WebfilterBugApplication {
public static void main(String[] args) {
SpringApplication.run(WebfilterBugApplication.class, args);
}
@WebFilter("/not/simple")
public static class SimpleFilterOne extends OncePerRequestFilter {
public static boolean CALLED = false;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
System.out.println("One");
CALLED = true;
filterChain.doFilter(request, response);
}
}
@WebFilter
public static class SimpleFilterTwo extends OncePerRequestFilter {
public static boolean CALLED = false;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
System.out.println("Two");
CALLED = true;
filterChain.doFilter(request, response);
}
}
@WebFilter(urlPatterns = "/not/simple")
public static class SimpleFilterThree extends OncePerRequestFilter {
public static boolean CALLED = false;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
System.out.println("Three");
CALLED = true;
filterChain.doFilter(request, response);
}
}
@RestController
@RequestMapping("/rest/simple")
public static class SimpleController {
@GetMapping
public String getString() {
return "Hello World";
}
}
} This will result in the |
@wilkinsona I'd like to take at look at this if that's ok. |
According to the Lines 33 to 36 in b4208ed
And according to the Lines 139 to 184 in b4208ed
So that at least explains why the |
Thanks for taking a look, @askneller. What you have described is this crux of the problem and I'm not yet sure how best to fix it. I think it's reasonable to expect |
I think the embedded boolean in I think we'll need to fix this at the |
Affects: 2.7.9 - 3.2.3 (Likely more, I just tested the latest and a random 2.7)
When using
@WebFilter
with either thevalue
orurlPatterns
fields defined, Spring fails to respect them. It would make sense that the following behaves the same.A repository configured with all three
WebFilter
variations and tests for them can be found here.The text was updated successfully, but these errors were encountered: