Springboot项目启动时报错
Cannot determine embedded database driver class for database type NONE
提示Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
原因是pom中引入了mybatis-spring-boot-starter
依赖 ,Spring boot默认会加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
类,DataSourceAutoConfiguration
类使用了@Configuration注解向Spring注入了DataSource bean。因为工程中缺少关于DataSource相关的配置信息,当Spring创建DataSource bean因缺少相关的信息就会报错。
解决方法:
可以在主程序上加@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
,如果加了这个注解之后又报错Attribute should be specified via @SpringBootApplication
就删了上述标签,直接在@SpringBootApplication
标签后加(exclude = {DataSourceAutoConfiguration.class})
搞定。
但要是你项目需要数据库,决不能配@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
,可以试试向pom依赖中添加依赖
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
借鉴:https://blog.youkuaiyun.com/Master_Shifu_/article/details/80420099