Springboot 禁用数据库自动配置
如果我们用SpringBoot实现一个简单的微服务,不需要数据库,你会发现在写完代码启动时会报org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''spring.datasource-org.springframework.boot.autoconfigur...
·
问题
在springboot项目,如果你在pom.xml里面加入 mybatis-spring-boot-starter 包,而在application.yml配置文件没有配置数据库连接信息,启动则会报错,如下:
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
解决方法
在Application类上增加:
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@Configuration
@ComponentScan(basePackages = {"com.example.demo"})
@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@EnableCaching
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
更多推荐
已为社区贡献2条内容
所有评论(0)