springboot生成的可执行jar运行错误------Failed to configure a DataSource: ‘url‘ attribute is not specified and
图片版文字版。
目录
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
而我用【java -jar jar包路径 】命令运行时,发现端口竟然还是默认的8080
3、解决
在启动命令中,指定springboot配置文件位置
java -jar springbootDemo-1.0-SNAPSHOT.jar --spring.config.location=classpath:./Application.yml
程序运行成功
4、分析错误原因
在idea运行时,springboot正确读取到了配置文件,为什么打成jar包,springboot却无法读取了呢?这是我疑惑的地方。
在仔细观察了项目的结构后,我发现springboot配置文件名错误,配置文件名中的A大写了,实际上名称是固定的application,但是在idea中却没有问题。。。。
5、参考文章
更多推荐
所有评论(0)