springboot application.properties不生效

早上上班以後,項目無論如何就是運行不起來,一直提示各種錯誤。後來一路排查發現是application.properties沒有生效導致的。本篇文章記錄一下排查過程。

開始一直提示 Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

完整錯誤提示如下:

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).

根據提示像是DataSource.url沒配的原因。但是很確定的是配置DataSource url了的。於是就想着重新運行一下試試,仔細觀察了一下idea控制檯輸出日誌,發現居然連port也編程默認的8080了,但是application.properties配置的是8002。這就算是定位到問題了,說明application.properties沒有生效。看了一眼target文件夾,application.properties文件沒有被自動複製到target文件夾下。

原因分析:

1.想着會不會是誰不小心把pom裏的packaging給設置錯了,可以將設置一下,改成jar。很快這個被推翻了,因爲並沒有改動。

2.想着還可能是誰不小心在子module裏面又加了一個module,雖然remove,delete,但是modules標籤與還在pom還在的原因。但是看了一下也不是這個原因。

3.想着會不會是誰不小心把pom的build->resource->include的規則給改了,於是在maven的pom.xml重新聲明include規則。改完以後運行試一下。發現好了。

解決方案:

在maven 的pom.xml下增加這段即可:

<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.*</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.*</include>
            </includes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

https://github.com/toutouge/javademosecond/tree/master/hellospringboot


作  者:請叫我頭頭哥
出  處:http://www.cnblogs.com/toutou/
關於作者:專注於基礎平臺的項目開發。如有問題或建議,請多多賜教!
版權聲明:本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文鏈接。
特此聲明:所有評論和私信都會在第一時間回覆。也歡迎園子的大大們指正錯誤,共同進步。或者直接私信
聲援博主:如果您覺得文章對您有幫助,可以點擊文章右下角推薦一下。您的鼓勵是作者堅持原創和持續寫作的最大動力!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章