Context:
- spring boot: 3.3.1
- spring cloud: 2023.0.2
I am trying to make a custom annotation having something like this:
@EnableAspectJAutoProxy
@Configuration
public class AspectJConfig {
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ServiceEvent {
}
@Component
@Aspect
@Slf4j
public class ServiceEventMethodAspect {
@Around("@annotation(ServiceEvent)")
public Object handleMethodCall(ProceedingJoinPoint joinPoint) throws Throwable {
try {
log.info("Service event called");
return joinPoint.proceed();
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
throw ex;
}
}
}
Now, I have 2 components:
@Component
public class TestServiceEvent {
@ServiceEvent
public String duplicate(String x) {
return x;
}
}
And the second one:
public interface DummyInterface {
}
@Component
public class TestDummyServiceEvent implements DummyInterface {
@ServiceEvent
public String duplicate(String x) {
return x;
}
}
In pom.xml I added a dependency on spring-boot-starter-aop
so aspectjweaver
is also in the classpath.
First one is called, second one is not. I suspect it is around implementing the interface and having different type of proxies (JDK vs CGLIB) but I failed to find any documentation which treats differently (from my code POV) these objects. Is there anyone who can point me on what I am doing wrong here?