I am currently migrating a project to Spring Boot and I have a custom method interceptor, which is used in some methods. However, when running the unit tests for the project, the custom interceptor is not being called. I am not sure if I should register the custom interceptor in some way in the tests or create a custom configuration in order for this interceptor to be called.
@Component
@Aspect
public class CustomInterceptor implements MethodInterceptor {
//custom logic
}
@CustomInterceptor
public Car getCar(final Car car) throws Exception {
//custom logic
}
While when I run the application itself the interceptor is working correct, it is not working in test environment. I have a configuration which is registering my interceptor as a bean in the following way
@Bean
public Advisor transactionalAdvisor() {
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression("@annotation(com.api.interceptor.CustomInterceptor)");
return new DefaultPointcutAdvisor(pointcut, customInterceptor);
}