1. 程式人生 > >class path resource [logback.xml] cannot be resolved to URL because it does not exist 問題解決

class path resource [logback.xml] cannot be resolved to URL because it does not exist 問題解決

今天在自己搭建Springboot 框架的時候,在配置 logging.config=classpath:logback.xml 出現找不到這個檔案的錯誤

經發現是maven的一個寫法問題,本來我是打算打算替換 .properties檔案中的內容,後面啟動的時候報錯,發現主要原因是

mavne 預設的resource會把src/main/resources中資原始檔全部放在claaapath目錄下,可是我自己重新定義已resource,只把./properties 檔案放入,所有導致找不到loback.xml檔案

<build>
    <resources>
<resource> <targetPath>${project.build.directory}/classes</targetPath> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include
>**/*.properties</include> </includes> </resource> </resources> </build>

 

正確的寫法如下:

<build>
    <resources>
            <resource>
                <targetPath>${project.build.directory}/classes</targetPath
> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/*.properties</include> <include>**/logback.xml</include> </includes> </resource> </resources> </build>

寫好以後,記得更新下maven,要不然有時候因為快取問題,而失效