springboot生成的可执行jar运行错误------Failed to configure a DataSource: ‘url‘ attribute is not specified and

目录

1、错误摘要

2、错误原因

表面原因

根本原因

发现过程

3、解决

4、分析错误原因 

5、参考文章

springboot版本2.6.7

1、错误摘要

图片版

2023-07-02 18:18:57.311  WARN 9012 --- [main] 
Error creating bean with name 'dataSource' defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/DruidDataSourceAutoConfigure.class]: Invocation of init method failed; 

nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class

***************************
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

文字版

Error creating bean with name 'dataSource' defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/DruidDataSourceAutoConfigure.class]: Invocation of init method failed; nested exception is 

org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class

***************************
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

2、错误原因

表面原因

在创建datasource时,没有指定数据源的url,导致初始化报错。

根本原因

Springboot应用没有读取到Application.yml配置文件,导致创建DataSource失败

发现过程

这是我的配置文件,启动设置了启动端口为80

springboot生成的可执行jar运行错误------Failed to configure a DataSource: ‘url‘ attribute is not specified and_第1张图片

 而我用【java -jar jar包路径 】命令运行时,发现端口竟然还是默认的8080

springboot生成的可执行jar运行错误------Failed to configure a DataSource: ‘url‘ attribute is not specified and_第2张图片

3、解决

在启动命令中,指定springboot配置文件位置

java -jar springbootDemo-1.0-SNAPSHOT.jar --spring.config.location=classpath:./Application.yml

程序运行成功

springboot生成的可执行jar运行错误------Failed to configure a DataSource: ‘url‘ attribute is not specified and_第3张图片

4、分析错误原因 

在idea运行时,springboot正确读取到了配置文件,为什么打成jar包,springboot却无法读取了呢?这是我疑惑的地方。

在仔细观察了项目的结构后,我发现springboot配置文件名错误,配置文件名中的A大写了,实际上名称是固定的application,但是在idea中却没有问题。。。。

springboot生成的可执行jar运行错误------Failed to configure a DataSource: ‘url‘ attribute is not specified and_第4张图片

 

5、参考文章

[1]Springboot 启动命令中添加 --spring.config.location不生效

[2]Spring Boot配置文件的位置和优先级

[3]彻底解决Failed to configure a DataSource:

你可能感兴趣的:(spring,boot,jar,后端)