I'm developing a jar library and trying to inject an interceptor from external jar library to Application.
For example:
public class MyExternalInterceptor implements HandlerInterceptor {
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
// Do something
}
}
I tried to using AOP in external libs but it's not working.
@Around("execution(* org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.addInterceptors(..))")
public Object aspect(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
// Tried to inject MyExternalInterceptor here
Object result = proceedingJoinPoint.proceed();
return result;
}
In Application using that lib:
@Configuration
public MyConfiguration extends WebMvcConfigurationSupport {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new SpringTestInterceptor()); // client's own interceptor
/* Add MyExternalInterceptor not explicitly but implicitly using AOP or other things */
}
}
Is there any way to inject an interceptor from external lib to App?
I know the question is very obscure (sorry for that), but could you give me any advice or hint to make it work?
Thank you for anyone who read my question :)
(I updated few more details for clarification)
WebMvcConfigurer
in both Client and library side instead of WebMvcConfigurationSupport
I use WebMvcConfigurer
instead of WebMvcConfigurationSupport
and change some codes like below:
@Configuration
public class MyExternalLibConfiguration implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new MyExternalInterceptor());
}
}
@Configuration
public MyConfiguration implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new SpringTestInterceptor()); // client's own interceptor
/* No need to add MyExternalInterceptor in here */
}
}
That's all! Everything is working well as M. Deinum said in comment.
Thank you again Deinum!
How to prevent a token created with OAuth 2.0 from expiring?
I have a project with complicated build setup (parent POM's with parent POM's) and so it happens that my compiler plugin executes with mavencompiler
I have a multi module maven project, the 3 modules are api, impl, allThe all module is a placeholder and has no source code, it only has a pom
I am using Camunda and I want to restart already completed processI am doing that using the following logic:
I want to achieve the following: