记录一次Springboot项目打包后运行出现’url’ attribute is not specified and no embedded datasource could be configured
问题描述
Springboot项目打包成jar,运行后出现如下描述的问题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
看似是没有找到url信息,实际上是没有找到properties文件
去pom.xml文件中手动配置一下
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</build>
然后打包jar,运行后又发现,虽然成功运行,但是访问什么页面都是
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Jan 11 21:56:31 CST 2022
There was an unexpected error (type=Not Found, status=404).
最后发现我的项目下的resources下放着我所有的静态文件static,但是上面代码说的<includes><include>**/*.properties</include></includes>
则表示仅打包这个类型的文件,所以访问资源的时候就会出现上图这种的情况
此时我们只需要把这些静态文件打包进去
<resource>
<directory>src/main/resources</directory>
<includes>
<include>static/**</include>
<include>**/*.properties</include>
</includes>
</resource>
或
<resource>
<directory>src/main/resources</directory>
</resource>
参考文章
https://www.hangge.com/blog/cache/detail_2887.html
https://www.cnblogs.com/wangxuchun/p/7501719.html
https://blog.youkuaiyun.com/gaoyipingzgh000/article/details/109600530