[英]Spring-Boot 2+ forces CGLIB proxy even with proxyTargetClass = false
The proxification setup seems to have changed between Spring-Boot 1.5+ and 2.+.代理设置似乎在 Spring-Boot 1.5+ 和 2.+ 之间发生了变化。
In Spring 1.5.20 with @EnableAspectJAutoProxy(proxyTargetClass = false) or just @EnableAspectJAutoProxy or even no annotation @EnableAspectJAutoProxy I would get a JdkDynamicAopProxy.在 Spring 1.5.20 中,使用 @EnableAspectJAutoProxy(proxyTargetClass = false) 或只是 @EnableAspectJAutoProxy 或什至没有注释 @EnableAspectJAutoProxy 我会得到一个 JdkDynamicAopProxy。 And with @EnableAspectJAutoProxy(proxyTargetClass = true) I would get CGLIB enhanced classes.
使用 @EnableAspectJAutoProxy(proxyTargetClass = true) 我会得到 CGLIB 增强类。 OK all good.
好的,一切都很好。
With the same code with Spring 2.1.4, I get a CGLIB enhanced ServiceImpl all the time whatever the config.使用与 Spring 2.1.4 相同的代码,无论配置如何,我始终获得 CGLIB 增强的 ServiceImpl。
I did not managed to have JdkDynamicAopProxy proxies with Spring 2+.我没有设法在 Spring 2+ 中使用 JdkDynamicAopProxy 代理。
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");
}
}
It's a known issue.这是一个已知问题。
Currently you can only set目前只能设置
spring.aop.proxy-target-class=false
in your config file to force it to use JDKProxy.在你的配置文件中强制它使用 JDKProxy。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.