Workaround resolve JAVA SpringBoot No subdirectories found for mandatory directory location ‘file:./config/*/’.
今天2021/6/1,幫公司POC SSO with SpringBoot時,遇到了一個新版SpringBoot 啟動上的錯誤,之前開發是指用SpringBoot 2.4.4並未遇到此問題,該問題是只要啟動就會顯示錯誤。
15:06:26.404 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: No subdirectories found for mandatory directory location 'file:./config/*/'.
at org.springframework.util.Assert.state(Assert.java:76)
at
... 以下省略Process finished with exit code 1
看了一下官方github issue中SpringBoot 2.4.6/2.5都有這樣的問題,在issue中有提供workaround 的解法,就是在環境變數或者是java 變數中加入config 參數,來避免這個問題。
java 參數為
--spring.config.location=optional:classpath:/,optional:classpath:/config/,optional:file:./,optional:file:./config/
環境變數為
SPRING_CONFIG_LOCATION=optional:classpath:/,optional:classpath:/config/,optional:file:./,optional:file:./config/
擇一使用就可以了。
原本無法啟動SpringBoot
加入JAVA參數後
專案可成功執行
也可以設定環境變數
專案可成功運行