0


springboot中Injection of resource dependencies failed

问题一:无非就是注解的问题,业务实现类加@Service,映射类加@Mapper、启动类上加上@MapperScan(basePackages = "xxx.xxx")以及@Resouce和@Autowired的使用(IDEA中最好使用@Resouce,倒不是说@Autowired有错,但是会报波浪线或者爆红,虽然不影响运行),这类问题没什么好说的,自己看一下漏什么补什么。

问题二:

 @Resource
 XXXMapper xMapper;

 @Resource
 YYYMapper xMapper;

 或者

 @Autowired
 XXXMapper xMapper;

 @Autowired
 YYYMapper xMapper;

名字起相同了,无论是引入service还是mapper,都不要把别名起一样,这样也会报这样的错误。

问题三:由于springboot的版本,有些依赖于springboot版本不搭配,也会报错,比如mybatis-plus,mybatis暂时没发现有什么问题。解决办法就是降低springboot的版本咯,是3.x.x的降低到2.x.x,重启就好了。

问题三:依赖包引入错误的,无论是web的还是resouce注解等的依赖包,最好看清楚再引入,例如:

import jakarta.annotation.Resource;(错误的)
   和
import javax.annotation.Resource;(正确的)

两个相差不大,将这些玩意删除重新引入就可以了................................

问题四:application.yml或者application.properties中的:

配置mybatis或者mybatis-plus
mybatis:
  mapper-locations: classpath:mapper/*.xml(需检查处)
  type-aliases-package: com.jiayi.quanyi.pojo(需检查处)
  configuration:
    map-underscore-to-camel-case: true 

或

mybatis-plus:
  mapper-locations: classpath:/mapper/*.xml(需检查处)
  configuration:
    log-impl: xxxx.xxxxx  (需检查处)
    call-setters-on-nulls: true 

看一下路径是否填错之类的,需要与自己项目目录路径完全一致即可。

.................................................................

其他的应该也没什么大问题了,还有什么问题的可以评论区说一下

标签: spring boot java spring

本文转载自: https://blog.csdn.net/m0_48516758/article/details/133013354
版权归原作者 bug生产师 所有, 如有侵权,请联系我们删除。

“springboot中Injection of resource dependencies failed”的评论:

还没有评论