With 2 configurations, in different jar files I would like to control the order of interceptor registration. One interceptor potentially relies on data set by the other.
I have tried @Order on the addInterceptors method.
@Configuration
public class PipelineConfig extends WebMvcConfigurerAdapter {
@Autowired
@Qualifier("Audit")
HandlerInterceptor auditInterceptor;
public PipelineConfig() {
}
@Order(2)
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(this.auditInterceptor);
}
}
And
@Configuration
public class ExecutionPipelineConfig extends WebMvcConfigurerAdapter {
@Autowired
@Qualifier("ExecutionContext")
HandlerInterceptor executionContextInterceptor;
public ExecutionPipelineConfig() {
}
@Order(1)
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(this.executionContextInterceptor);
}
}
React Full Stack Web Development With Spring Boot To work with interceptor, you need to create @Component class that supports it and it should implement the HandlerInterceptor interface. preHandle() method − This is used to perform operations before sending the request to the controller.
Also, you can have as many implementations of WebMvcConfigurer as you want in a Spring project. So, if you need to define some common interceptors in the Common module, you can extend the AbstractWebMvcConfigurerImpl in the common module also.
DispatcherServlet is the front controller in Spring Web MVC. Incoming requests for the HTML file are forwarded to the DispatcherServlet.
The spring framework documentation [ http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/ ] specifies that @Order
is used for :
The @Order
annotation can be applied in your case at class level for your configurations if your spring version >4.2.
For example:
@Configuration
@Order(2)
public class PipelineConfig extends WebMvcConfigurerAdapter {
Also this coudld be a usecase for the @Import annotation for aggregating @Configuration files(http://docs.spring.io/spring-javaconfig/docs/1.0.0.M4/reference/html/ch04s03.html)
If, on the other hand, one of your interceptors potentially rely on data/beans you can use the @DependsOn("beanName")
annotation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With