When the AOP autoconfiguration is turned off with attribute spring.aop.auto=false
, it is ineffective to open the JDK agent with @EnableAspectJAutoProxy
, the cglib agent is still in use ,And I'm sure my class implements the interface !!!
It is recommended to remove AOP automatic configuration class of org.springframework.boot.autoconfigure.aop.AopAutoConfiguration
Comment From: wilkinsona
Thanks for the report but it's hard to tell what's happening from 3 screenshots. I'm not sure what you mean by "It is recommend to remove AOP automatic configuration". When spring.aop.auto
is set to false
, AopAutoConfiguration
should have no effect as it is conditional on spring.aop.auto
not being set at all or being set to true
.
If you would like us to spend some more time investigating, please spend some time providing a minimal sample that reproduces the problem. A project shared as a separate repository on GitHub or zipped and attached to this issue would be ideal.
Comment From: snicoll
potential duplicate of #16516
Comment From: brucelwl
potential duplicate of #16516
@snicoll Yes, it looks like the same problem
Comment From: wilkinsona
I don't think it's the same problem. As far as I can tell, #16516 is specific to proxies created for classes with @Async
methods and there don't appear to be any such methods in this case.
@brucelwl please provide a minimal sample so that we can be sure of exactly what we're looking at.
Comment From: brucelwl
@wilkinsona @snicoll This is my example code, https://github.com/brucelwl/boot-bug-demo.git
Comment From: wilkinsona
Thanks for the example code. spring.aop.auto
only affects the auto-configuration of @EnableAspectJAutoProxy
. It does not affect the type of proxies that are created when using @Transactional
and the auto-configured @EnableTransactionManagement
. The proxy type created for classes with @Transactional
methods is controlled by spring.aop.proxy-target-class
. Setting that to false
will result in JDK proxies being created:
With this change in place, your example produces the following output:
MathCalculatorServiceI should be proxyed by JDK instead of using cglib proxy
class com.sun.proxy.$Proxy57
Comment From: brucelwl
@wilkinsona @snicoll Please note that I used @EnableAspectJAutoProxy
on the startup class myself, but it didn't work that way
Comment From: wilkinsona
@EnableAspectJAutoProxy
and its proxyTargetClass
attribute has no effect on @EnableTransactionManagement
and its proxyTargetClass
attribute. That is the case with both Spring Framework when things are being configured manually and with Spring Boot when things are being auto-configured. If you had used @EnableTransactionManagement(proxyTargetClass=false)
things would have behaved as you wanted.
Unlike individual @Enable…
annotations, spring.aop.proxy-target-class
does affect the proxy configuration of multiple components. When using auto-configuration it affects proxies used for AOP, method validation, persistence exception translation, and transaction management.
Comment From: brucelwl
@wilkinsona Thanks for the reply, I know the reason, because "org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration.EnableTransactionManagementConfiguration" also has its automatic configuration.