最近同事在合代码的时候出现了这个报错:

错误提示:

// 看字面意思很简单:提示找不到包,加了各种注解也无济于事,比如:@Repository、@ComponentScan等
Field shuShuDao in com.xxx.data.service.impl.xxxxImpl required a bean of type 'com.xx.xx.xx.xx.xxx.daoName' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.xx.xx.xx.xx.xxx.daoName' in your configuration.


Process finished with exit code 1

具体过程就是我的代码在原项目可以正常运行,他将我的代码照搬过来后却一直报这个错,我确认了导包的位置无误,注解无误,后来觉得好像是启动时的包扫描范围有误,范围太小,所需导包在扫描范围之外,导致未找到包,经查验证后确实是这样的

上原代码截图:

可以看到项目启动时扫描的db包范围限制gmssdk包下!
再来看下我的包位置:和gmssdk平级,导致扫描不到所以报错,找不到该包

正确写法:扫描包的路径到db就可以了


项目正常启动:也不需要之前往dao层加的那些花里胡哨的注解!

方法二:这里简单说下另一种方法:
@ComponentScan(value = “com.xx.xx.packageName”)这个注解可以用来指定包配置,指定扫描组件、规则等,想了解的可以再查下

更多推荐

IDEA项目启动报错:Consider defining a bean of type ‘com.xx.xx.xx.xx.xxx.daoName‘ in you