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 FAILED TO START
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).
在做多模块任务启动时,遇到了这个错误
错因有三:
1、检查application.properties或者application.yml文件配置文件:
#设置数据库连接配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/XXXX?serverTimezone=Asia/Shanghai
spring.datasource.username=xxx
spring.datasource.password=xxxxxx
2、target 文件夹下yml或者properties文件没有被扫描到:
需要在pom.xml文件中添加如下.来保证文件都能正常被扫描到并且加载成功。
<!--手动指定文件夹为resources-->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**.*.yml</include>
<include>**.*.yaml</include>
</includes>
</resource>
</resources>
3、配置文件出现配置覆盖
这也是我报错的原因!!!!
因为我再没有分模块写代码的时候顺手将springboot启动模块的配置文件改成了yml文件,以至于加载配置文件的时候读取了空白的配置文件,导致数据库连接不上!
可能是由于我mapper层模块的配置文件也是yml文件,所以就没有读取我的文件配置
所以只需要将springboot启动模块的配置文件重写改成properties文件就可以了!
注:
两者的加载顺序
正常的情况是先加载yml,接下来加载properties文件。如果相同的配置存在于两个文件中。最后会使用properties中的配置。最后读取的优先集最高。
两个配置文件中的端口号不一样会读取properties中的端口号
如果本篇文章对你有帮助,还请一键三连【开心】