Description:
Field userMapper in com.haitao.service.impl.UserServiceImpl required a bean of type ‘com.haitao.mapper.UserMapperChan’ 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.haitao.mapper.UserMapperChan’ in your configuration.
解决方法
在启动类上添加 @mapperScan注解
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@MapperScan(basePackages = “com.haitao.mapper”)
public class EmployeeManagerSystemBackApplication {
public static void main(String[] args) {
SpringApplication.run(EmployeeManagerSystemBackApplication.class, args);
}
}
这篇博客讨论了在启动Spring Boot应用程序时遇到的一个常见问题:FielduserMapperChan在UserServiceImpl中无法找到合适的bean。解决方案是在启动类上添加@MapperScan注解,指定mapper接口所在的包名,例如`@MapperScan(basePackages = com.haitao.mapper)`。这样做可以确保Spring能够扫描并正确注入所需的mapper bean。
2628

被折叠的 条评论
为什么被折叠?



