Field userrepository in com.example.demo2.service.imp.UserServiceImp required a bean of type ‘com.ex

Spring Boot projects may encounter classes in the DAO layer that cannot be injected, as indicated below

Field XXXXXpository in required a bean of type that could not be found.

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

My solution for my project is to add @ComponentScan(basePackages = {” package name “}) to the startup class. This annotation allows the application to scan the configuration under dao at a specified location. The package name should be written to the package containing mapper, starting from the first package in the Java file. Such as: com. Example. Demo2. Dao

Read More: