-
[武汉|结业弟子]JAVA-方广辉0
SpringBoot启动失败,Bean配置失败
原因:在mybatis-spring-boot-autoconfigure的jar包中有一个类 MybatisAutoConfiguration,在这个类中的registerBeanDefinitions方法告诉了我们
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
logger.debug("Searching for mappers annotated with @Mapper");
ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
try {
if (this.resourceLoader != null) {
scanner.setResourceLoader(this.resourceLoader);
}
List<String> packages = AutoConfigurationPackages.get(this.beanFactory);
if (logger.isDebugEnabled()) {
for (String pkg : packages) {
logger.debug("Using auto-configuration base package '{}'", pkg);
}
}
scanner.setAnnotationClass(Mapper.class);
scanner.registerFilters();
scanner.doScan(StringUtils.toStringArray(packages));
} catch (IllegalStateException ex) {
logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled.", ex);
}
}
解决方案
1、mapper(Dao层)
添加 @Mapper
2、在启动类
@MapperScan(value = "com.xxxxx.dao")
SpringBootApplication
@MapperScan(value = "com.ptteng.academy.Mapper")
public class HomeWebApplication {
public static void main(String[] args) {
SpringApplication.run(HomeWebApplication.class, args);
}
}编辑于2018-10-13
- 去第 页