600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > The bean ‘xxx‘ could not be injected as a ‘com.dmo.service.xx‘ because it is a JDK dynamic proxy

The bean ‘xxx‘ could not be injected as a ‘com.dmo.service.xx‘ because it is a JDK dynamic proxy

时间:2023-10-11 03:52:50

相关推荐

The bean ‘xxx‘ could not be injected as a ‘com.dmo.service.xx‘ because it is a JDK dynamic proxy

原因:springboot 开启了事务支持1.启动类加了@EnableTransactionManagement2.service的实现类加了@Transactional报错:Description:The bean 'ParkingServiceImpl' could not be injected as a 'com.dmo.parkingview.service.Impl.ParkingServiceImpl' because it is a JDK dynamic proxy that implements:com.dmo.parkingview.service.ParkingService描述:我在其他的类中注入了ParkingServiceImpl这个bean 失败了,因为springboot的事务默认是使用jdk的动态代理,即基于接口,所以改为注入ParkingService就可以了。spring给的解决: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可以考虑下将action中注入的Bean改成接口方式或者强迫事务使用CGLib代理方式(基于类,即设置proxyTargetClass=True在启动事务管理上@EnableTransactionManagement(proxyTargetClass=True)),这种以CGLib代理方式进行,按照之前写法,我们应该是需要引入相应的cglib库的jar包。而在springboot中已经集成了。但在spring3.2之前是需要引入的;假如你是在不想将注入的Bean改成接口方式,非得要用实现类,而且还不想再启动事务时配置proxyTargetClass=true,那么,有如下方法:在你Service层对应的实现类上配置@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)注解,表明此类上所有方法上的事务都是CGLib方式代理的,问题照样可以解决。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。