- 我正在使用 spring-context 5.3.13(沒有 spring-boot)
- 我在“src/main/resources”下有一個名為“config.yaml”的檔案
- 我配置了這個@PropertySource:
@PropertySource(value = "classpath:config.yaml", factory = TypesafeAdapterPropertySourceFactory.class) - 當我從 intellij 運行它時,它成功加載了檔案
我的問題:運行 jar 時,由于 jar 內的路徑不可用,找不到檔案。更多資訊:
- 檔案本身在 jar 根目錄內(檢查它)
- 例外:
執行緒“main” org.springframework.beans.factory.BeanDefinitionStoreException 中的例外:無法決議配置類 [com.viber.httpmsexample.Application];嵌套例外是 java.io.FileNotFoundException: 類路徑資源 [config.yaml] 無法決議為絕對檔案路徑,因為它不駐留在檔案系統中:jar:file:/C:/Repositories/http-ms-example/ target/app.jar!/config.yaml at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:189) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331) at org .springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247) 在 org.springframework.context。
我可以將這個配置外部化,但我希望暫時保留它。有沒有可能克服這個問題?
謝謝!
uj5u.com熱心網友回復:
問題出在您自己的問題上TypesafeAdapterPropertySourceFactory,它試圖根據File檔案在 jar 中時不起作用的a 創建屬性源。java 意義上的 File 是檔案系統上的物理檔案,存檔中的檔案不是。
我強烈建議使用ResourcePropertySource來創建屬性源并裝飾它而不是其他東西。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/370025.html
下一篇:CrudRepository<TourClaimModel,Integer>型別中的save(S)方法不適用于引數(List<TourClaimModel>)
