zoukankan      html  css  js  c++  java
  • SpringBoot注入Service失败

    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中已经集成了。

  • 相关阅读:
    4.23上机练习
    4.17java作业
    4.16java作业
    leetcode 189
    leetcode 172
    leetcode 171
    leetcode 169
    win10内网外网智能访问
    leetcode 168
    leetcode 165
  • 原文地址:https://www.cnblogs.com/phyqxx/p/11572239.html
Copyright © 2011-2022 走看看