springboot xxxServiceImpl 无法 跨module 注入 xxxDao问题

错误描述:

Description:

Field xxxDao in com.abc.web.service.impl.PostServiceImpl required a bean of type 'com.abc.core.dao.PostDao' that could not be found.


Action:

Consider defining a bean of type 'com.abc.core.dao.PostDao' in your configuration.

问题描述:

xxxDao、xxxDaoImpl在module(abc-core)

xxxService、xxxServiceImpl在module(abc-web)

 

解决方法

  1. @ComponentScan("com.abc")

  2. ​​​​​​@ComponentScan(basePackages = {"com.abc.core", "com.abc.web"})

  3. @SpringBootApplication(scanBasePackages = "com.abc")

三种方法都无效,求老司机解答?跪谢。。。

 

附other弃坑大法:

关于spring boot自动注入出现Consider defining a bean of type 'xxx' in your configuration问题解决方案

SpringBoot 多模块项目(module)Service自动注入(@Autowired)

Spring Boot @Autowired 没法自动注入的问题

IDEA搭建Spring boot问题集

多模块配置

https://blog.csdn.net/sinat_36304803/article/details/81512589

根据提供的引用内容,nacos启动报错ERROR Startup errors : org.springframework.beans.factory.UnsatisfiedDependencyException,这个错误通常是由于依赖注入问题引起的。具体来说,可能是某个bean的依赖项无法满足,或者依赖项没有正确注入。解决此问题的方法如下: 1.检查nacos配置文件是否正确,特别是数据库连接信息是否正确。 2.检查nacos依赖项是否正确,特别是版本是否匹配。 3.检查nacos启动日志,查看哪个bean无法满足依赖项,然后检查该bean的依赖项是否正确注入。 4.如果无法确定问题所在,可以尝试使用调试器进行调试,以查找问题。 下面是一个可能的解决方案: ```java org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘xxxController’: Unsatisfied dependency expressed through field ‘xxxService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘xxxServiceImpl’: Unsatisfied dependency expressed through field ‘xxxRepository’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘xxxRepository’: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.xxx.xxx.xxx ``` 根据上述错误信息,我们可以看到,xxxRepository这个bean的初始化方法失败了,原因是它不是一个受管理的类型。这通常是由于没有在应用程序上下文注册该类型引起的。解决此问题的方法是在应用程序上下文注册该类型,例如: ```java @Configuration @EnableJpaRepositories(basePackages = "com.xxx.xxx.xxx") @EntityScan(basePackages = "com.xxx.xxx.xxx") public class AppConfig { // ... } ```
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值