The proxification setup seems to have changed between Spring-Boot 1.5+ and 2.+.
In Spring 1.5.20 with @EnableAspectJAutoProxy(proxyTargetClass = false) or just @EnableAspectJAutoProxy or even no annotation @EnableAspectJAutoProxy I would get a JdkDynamicAopProxy. And with @EnableAspectJAutoProxy(proxyTargetClass = true) I would get CGLIB enhanced classes. OK all good.
With the same code with Spring 2.1.4, I get a CGLIB enhanced ServiceImpl all the time whatever the config.
I did not managed to have JdkDynamicAopProxy proxies with Spring 2+.
Is there still a way to do it ?
Here is my code:
@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass = false)
public class DemoApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);
MyService service = context.getBean(MyService.class);
service.execute();
}
}
@Aspect
@Component
public class ChronoAspect {
@Around("execution(* com.example.demo.service..*.*(..))")
public Object chronoAround(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
// .....
}
}
public interface MyService {
void execute();
}
@Component
public class ServiceImpl implements MyService {
public void execute() {
System.out.println("Hello execute from Service.execute");
}
}