English is not my first language, please email zhangbin.zj@gmail.com if not understand my description.
environment: springboot: 2.1.3.RELEASE
describe:
I use @Transactional(rollbackFor = Exception.class)
in my service method, and config
spring:
aop:
auto: true
proxy-target-class: true
but, spring still report
TransactionAutoConfiguration.EnableTransactionManagementConfiguration.CglibAutoProxyConfiguration matched:
- @ConditionalOnProperty (spring.aop.proxy-target-class=true) matched (OnPropertyCondition)
AopAutoConfiguration.JdkDynamicAutoProxyConfiguration:
Did not match:
- @ConditionalOnProperty (spring.aop.proxy-target-class=false) found different value in property 'proxy-target-class' (OnPropertyCondition)
and suggest me
Action:
Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @EnableAsync and/or @EnableCaching.
if I remove the annotation,success. why?
Comment From: toby1024
@Bean
public static DefaultAdvisorAutoProxyCreator getDefaultAdvisorAutoProxyCreator() {
DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
// if not set this, it will use JDK dynamic proxy
defaultAdvisorAutoProxyCreator.setProxyTargetClass(true);
return defaultAdvisorAutoProxyCreator;
}
in org.springframework.aop.framework.ProxyConfig proxyTargetClass is false,if not set.
private boolean proxyTargetClass = false;
is it an issue?
Comment From: wilkinsona
It looks like the suggestion is misleading as CGLib-based proxies are already being used. They are the default and you've also explicitly configured their used by setting spring.aop.proxy-target-class
to true
.
So that we can understand the problem and verify that the suggestion is misleading, can you please provide a minimal example that reproduces the behaviour you have described?
Comment From: toby1024
It looks like the suggestion is misleading as CGLib-based proxies are already being used. They are the default and you've also explicitly configured their used by setting
spring.aop.proxy-target-class
totrue
.So that we can understand the problem and verify that the suggestion is misleading, can you please provide a minimal example that reproduces the behaviour you have described?
use shiro:
dependencies {
compile 'org.apache.shiro:shiro-spring:1.4.0'
}
and config shiro
@Configuration
public class ShiroConfig {
...
@Bean
public static DefaultAdvisorAutoProxyCreator getDefaultAdvisorAutoProxyCreator() {
return new DefaultAdvisorAutoProxyCreator();;
}
}
set proxy-target-class: true in application.yml
spring:
aop:
auto: true
proxy-target-class: true
then use @Transactional(rollbackFor = Exception.class) on method it will report
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'xxxService' could not be injected as a 'a.b.c.xxxService' because it is a JDK dynamic proxy that implements:
Action:
Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @EnableAsync and/or @EnableCaching.
it look's like the application.yml config not rewrite the properties proxyTargetClass in the DefaultAdvisorAutoProxyCreator‘s super class ProxyConfig.
in ProxyConfig
public class ProxyConfig implements Serializable {
private static final long serialVersionUID = -8409359707199703185L;
private boolean proxyTargetClass = false;
private boolean optimize = false;
boolean opaque = false;
boolean exposeProxy = false;
private boolean frozen = false;
...
}
in springboot 2.1.3, the proxyTargetClass default is false
Comment From: wilkinsona
You are creating your own DefaultAdvisorAutoProxyCreator
which tells Spring Boot that you want to take control. You should either remove the bean entirely (as I suspect it is not needed) or configure it to meet your needs.
Comment From: ghost
同样的问题,除了自定义DefaultAdvisorAutoProxyCreator 或者 在bean上@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS),还有其他解决办法吗
Comment From: wilkinsona
From Google translate:
The same problem, apart from customizing
DefaultAdvisorAutoProxyCreator
or@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
on the bean, is there any other solution?
As far as we know, there shouldn't be a problem to solve by default. The problem described in this issue only occurred because DefaultAdvisorAutoProxyCreator
was already being customised in a way that didn't meet the user's needs.
If you have a problem where you are using the default proxy creation configuration and proxy-target-class is not having an effect and you would like us to investigate, please open a new issue with a minimal samples that reproduces the problem.