问题

在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);
	}
}
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐