簡體   English   中英

無法從 spring 引導應用程序中的非默認位置加載 Ignite 配置 spring bean 定義

[英]Unable to load Ignite config spring bean definition from non default location in spring boot application

我正在嘗試在我的 spring 啟動應用程序中外部化我的 ignite 配置,以便可以在不重建 jar 的情況下更改配置。

以前該文件位於 src/main/resrouces 並通過注釋加載。

@ImportResource("IgniteConfig.xml") and 

@Autowired 
private IgniteConfiguration cfg;

當我將 IgniteConfig.xml 移動到可執行文件 jar 旁邊的配置文件夾時,上述停止工作,我嘗試了以下操作但沒有成功:

  1. 使用 --spring.config.location 參數。 我可以說這是在運行時拾取的,因為其他配置工作,但上面的 ImportResource 注釋說文件 IgniteConfig.xml 找不到。

  2. 使用 Ignition.start 的相對路徑(例如 ./config.IgniteConfig.xml)。 我導致此相對路徑在我的日志中打印 xml 文件的文件內容,但是當我將其傳遞給 Ignition.start 時,它說找不到該文件。 我嘗試過使用相對和絕對路徑來做到這一點。

  3. 手動創建一個 ApplicationContext 並通過 bean 名稱獲取配置。

ApplicationContext context = new ClassPathXmlApplicationContext("./config/IgniteConfig.xml");

這再次抱怨該文件不存在,即使我可以通過直接打開文件看到:

File igniteConfigFile = new File("./config/IgniteConfig.xml");

konqi 在這篇文章中的評論回答了我的問題:

“如果您要導入類路徑之外的資源,則語法為:

@ImportResource( { "file:path/spring-context1.xml", "file:path/spring-context2.xml" } ) 

"

就我而言,我只需要這樣做:

@ImportResource( { "file:./config/IgniteConfig.xml" } )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM