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.
Read More:
- SpringBoot Access Clickhouse Error: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘jdbcConverter’ defined in class path resource [***.class]
- Eureka unit test error creating bean with name ‘Eureka autoservice registration’: Singleton bean
- [Solved] Error creating bean with name rController‘: Unsatisfied dependency expressed through field
- Error creating bean with name ‘studentMapper‘ defined in file
- [Solved] org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘dataSource‘
- [Solved] Springboot Error creating bean with name ‘dataSource’ defined in class path resource
- How to Solve Error creating bean with name ‘log’loginController’
- [Solved] nacos Startup Error: Error creating bean with name ‘authFilterRegistration‘ defined in class path resource
- Error creating bean with name ‘captchaController‘: Unsatisfied dependency expressed through field ‘c
- Spring cloud Eureka error creating bean with name
- [Solved] renren-fast Startup Error: Error creating bean with name ‘scheduleJobController‘
- [Solved] Error creating bean with name ‘sqlSessionFactory‘ defined in class path resource
- Error creating bean with name ‘redistemplate’ defined in class path resource
- [Solved] Redis Error: Error creating bean with name stringRedisTemplate defined in class path resource
- [Solved] JWT + SSO Error: Error creating bean with name ‘jwtTokenServices’
- Tk.mapper Common mapper Error: Error creating bean with name ‘commonMapper‘ defined in file xxx
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘globalTransa
- When integrating redis with SSM framework, error creating bean with name ‘rediscontentserviceimpl’ defined in file
- [Solved] springmvc:Error creating bean with name ‘org.springframework.cache.interceptor.CacheInterceptor
- [Solved] Error creating bean with name ‘enableRedisKeyspaceNotificationsInitializer‘ defined in class path re