IDEA project startup error: Consider defining a bean of type'com.xx.xx.xx.xx.xxx.daoName' in your conf

Recently, my colleagues reported this error when they were cooperating with the code:

Error message:

// 看字面意思很简单:提示找不到包,加了各种注解也无济于事,比如:@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

The specific process is that my code can run normally in the original project. After he copied my code, he kept reporting this error. I confirmed that the location of the guide package was correct and the annotations were correct. Later, it seemed that the package scan range at startup was incorrect. , The range is too small, and the required guide package is outside the scanning range, resulting in the package not being found. This is indeed the case after verification

Screenshot of the original code:
Insert picture description here

You can see that the scope of the db package scanned when the project starts is limited to the gmssdk package!
Let's take a look at the location of my package again: it is at the same level as gmssdk, which results in an error that cannot be scanned and the package cannot be found.
Insert picture description here
Correct writing: scan the path of the package to db.

Insert picture description here
The project starts normally: there is no need to go to the dao layer to add those fancy comments!
Insert picture description here
Method 2: Here is a brief
description of another method: @ComponentScan(value = "com.xx.xx.packageName") This annotation can be used to specify package configuration, specify scanning components, rules, etc. You can check again if you want to know
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_42258975/article/details/109467836
Recommended