关于“Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.”
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).
错误原因:
显然,根据错误原因可知找不到数据源配置。但是由于依赖方提供的API依赖中引用了一些多余的依赖触发了该自动化配置的加载,详情查看:https://blog.csdn.net/dyc87112/article/details/73739535,导致数据源配置自动启动生效。
这里是由于依赖了:
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.1</version> </dependency>
解决方案:
1.不配置数据源的情况下:
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, MailSenderAutoConfiguration.class})
详细请参考:https://zhuanlan.zhihu.com/p/96508798
2.配置数据源:本文数据源配置在yml文件中:
spring: datasource: url: jdbc:mysql://xxxxxxxxxx username: xxx password: xxx driver-class-name: com.mysql.jdbc.Driver
注意:pom文件中package类型不能为pom,否则项目编译后target中没有yml配置文件,同理打包后jar包中也没有yml配置文件。
如下位置:
<groupId>com.xxx</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo</name>
<!--<package>pom</package>--> <description>Demo project for Spring Boot</description>
以上!