Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

配置aop-patterns之后导致@EnableTransactionManagement的属性proxyTargetClass设置无效 #2330

Closed
qq592304796 opened this issue Feb 9, 2018 · 6 comments
Labels
Milestone

Comments

@qq592304796
Copy link

设置Spring监控AOP切入点
spring.datasource.druid.aop-patterns=xxx

导致@EnableTransactionManagement的属性proxyTargetClass设置无效

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.

必须设置spring.aop.proxy-target-class=true才得以解决这个问题

@wenshao
Copy link
Member

wenshao commented Feb 9, 2018

@lihengming

@wenshao wenshao added the Bug label Feb 9, 2018
@wenshao wenshao added this to the 1.1.8 milestone Feb 9, 2018
@lihengming
Copy link
Contributor

@qq592304796 哈喽,我配置了spring.datasource.druid.aop-patterns并且加了@EnableTransactionManagement(proxyTargetClass =true) 问题没有重现,是不是还有其他的必要条件?

@qq592304796
Copy link
Author

public class ServiceAImpl implements ServiceA {
      ....
}

public class ServiceAImpl implements ServiceA {
       /**
      *  这里注入ServiceAImpl会报错
      */
      @Autowired
       private ServiceAImpl serviceAImpl; 
      ....
}

@EnableTransactionManagement(proxyTargetClass =true)
配置proxyTargetClass =true之后,ServiceAImpl是可以成功注入

但是设置Spring监控AOP切入点之后
spring.datasource.druid.aop-patterns=xxx

启动程序报错
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.

版本:release-1.1.6

@lihengming
Copy link
Contributor

lihengming commented Feb 9, 2018

哦,知道了,应该和@EnableTransactionManagement(proxyTargetClass =true)没关系,我创建 DruidAop时默认设置 proxyTargetClass 是false,导致是按接口进行代理的,而不是实现类,这个问题其实你把 @Autowired private ServiceAImpl serviceAImpl; 修改为 @Autowired private ServiceA serviceAImpl; 也是可以解决的,类型声明为接口类型,而不是实现类型。

@lihengming
Copy link
Contributor

lihengming commented Feb 9, 2018

我将proxyTargetClass的默认设置修改为 true 吧,省的你们麻烦,1.1.8版本解决。

wenshao added a commit that referenced this issue Feb 9, 2018
@wenshao
Copy link
Member

wenshao commented Feb 11, 2018

https://github.com/alibaba/druid/releases/tag/1.1.8
问题已修复,请使用新版本

@wenshao wenshao closed this as completed Feb 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants