Description:
The bean 'userService' could not be injected as a 'com.phy.hemanresoruce.service.UserService' 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.
1.
根據上面描述,注入userServiceImpl這個Bean時失敗,(失敗的原因就是實現接口,而springboot的事務默認是使用jdk的動態代理,即基於接口))。在action層中注入的Bean是實現類,因此就會報錯。
解決:將此注入Bean的方式改成了其接口
2.
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.
再看一下idea給的建議:可以考慮下將action中注入的Bean改成接口方式或者強迫事務使用CGLib代理方式(基於類,即設置proxyTargetClass=True在啟動事務管理上@EnableTransactionManagement(proxyTargetClass=True)),這種以CGLib代理方式進行,按照之前寫法,應該是需要引入相應的cglib庫的jar包。而在springboot中已經集成了。