Springboot專案本地執行無問題而打成jar包出現問題Failed to auto-configure a DataSource
阿新 • • 發佈:2021-01-27
如題,完整報錯如下:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-01-26 02:08:50.556 ERROR 4152 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
* **************************
Description:
Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-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).
由報錯資訊可以看出問題是沒有配置資料來源,而明顯我的配置檔案裡是有配置DataSource的,找了很久才發現問題,就是打包的時候沒有把配置檔案載入進去。
所以應該在pom檔案中加入resources標籤中程式碼即可
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</build>