Error message:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘com.xubo.mybatisplus.MyBatisPlusTest’: Unsatisfied dependency expressed through field ‘userMapper’; of type ‘com.xubo.mybatisplus.mapper.UserMapper’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
problem causes:
This is because mapperscan is not added to the startup class; the corresponding class cannot be scanned.
Add @MapperScan(“com…*.dao”) to the startup class; the problem is solved!
My own actual problem is to add it, but what I wrote is the path of the specific class, with the class name, so it doesn’t work, you must write the package name. Change it to the package name and start querying data successfully.
@MapperScan function : specify the package where the interface to be implemented class is located, and then all interfaces under the package will generate corresponding implementation classes after compilation
Add location: add above the Springboot startup class
The following paragraph is what I saw when I searched, and I don’t know its correctness. For more than an hour, I inadvertently researched that the location of the springboot startup class, in addition to the first principle, only scans the annotations of the same level directory and subdirectory where it is located, and at the same time the startup class is separated from the directory java by at least two layers of packages.