Comments (2)
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 SpringBootMockMvcBuilderCustomizer
but their urlPatterns collection is empty.
from spring-boot.
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 @WebFilter
you should not use @Component
. Instead, you should enable scanning for servlet components using @ServletComponentScan
:
@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 @WebFilter
s being found and their attributes being honored when it's started using its main method. Unfortunately, it doesn't fix the tests as I have just discovered that the registration of servlet components doesn't work in a mock web environment. It works with @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
but not with the default mock environment. We can use this issue to fix that.
from spring-boot.
Related Issues (20)
- NoClassDefFoundError after migrating to spring boot 3.2.0 HOT 9
- Add link metadata in spring-boot-dependencies
- 请问一下,你们的发明在**被申请了专利。 HOT 1
- Configure a suitable Jackson object pool when virtual threads are enabled HOT 3
- Fix typo in Custom HTTP Exchange Recording section
- Fix typo in Custom HTTP Exchange Recording section
- SpringProfile arbiter fails without a Spring's environment
- SpringProfile arbiter fails without a Spring's environment
- @DisabledIfProcessUnavailable("docker") can hang indefinitely
- @DisabledIfProcessUnavailable("docker") can hang indefinitely
- @DisabledIfProcessUnavailable("docker") can hang indefinitely
- Auto-configure a bootstrapExecutor bean to be used by Framework's background bean initialization
- Resolving a BuildpackReference created from a URL-like String can fail on Windows
- Resolving a BuildpackReference created from a URL-like String can fail on Windows
- Resolving a BuildpackReference created from a URL-like String can fail on Windows
- how to resolve this exception: com.oracle.svm.core.jdk.UnsupportedFeatureError: SerializationConstructorAccessor HOT 1
- In spring-boot version 3.2.3, interceptors are not called in order of addition in InterceptorRegistry HOT 1
- Building images fails with Docker 24.0 & Spring-Boot 3.2.3 on windows server 2019 HOT 7
- Remove redpanda image compatibility
- When using Logback, log messages appear in a single line when application name contains brackets
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-boot.