简体   繁体   English

无法从 spring 引导应用程序中的非默认位置加载 Ignite 配置 spring bean 定义

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

I am trying to externalize my ignite configuration in my spring boot application so the configuration can be changed without rebuilding the jar.我正在尝试在我的 spring 启动应用程序中外部化我的 ignite 配置,以便可以在不重建 jar 的情况下更改配置。

Previously the file resided in src/main/resrouces and was loaded via annotations.以前该文件位于 src/main/resrouces 并通过注释加载。

@ImportResource("IgniteConfig.xml") and 

@Autowired 
private IgniteConfiguration cfg;

When I moved the IgniteConfig.xml to the config folder that resides next to the excutable jar the above stopped working and I have tried the following without success:当我将 IgniteConfig.xml 移动到可执行文件 jar 旁边的配置文件夹时,上述停止工作,我尝试了以下操作但没有成功:

  1. use --spring.config.location argument.使用 --spring.config.location 参数。 I can tell this is picked up during run time as other configurations work but the above ImportResource annotation says the file IgniteConfig.xml cannot be found.我可以说这是在运行时拾取的,因为其他配置工作,但上面的 ImportResource 注释说文件 IgniteConfig.xml 找不到。

  2. use a relative path to (eg ./config.IgniteConfig.xml) to Ignition.start.使用 Ignition.start 的相对路径(例如 ./config.IgniteConfig.xml)。 I cause this relative path to print the file contents of the xml file in my logs but when I pass it to Ignition.start it says the file cannot be found.我导致此相对路径在我的日志中打印 xml 文件的文件内容,但是当我将其传递给 Ignition.start 时,它说找不到该文件。 I have tried using relative and absolute paths to do this.我尝试过使用相对和绝对路径来做到这一点。

  3. Manually create an ApplicationContext and get the configuration by bean name.手动创建一个 ApplicationContext 并通过 bean 名称获取配置。

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

This again complains that the file does not exist even though I can see by opening the file directly:这再次抱怨该文件不存在,即使我可以通过直接打开文件看到:

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

The comment by konqi in this post answered my question: konqi 在这篇文章中的评论回答了我的问题:

"In case you want to import a resource that is outside the classpath the syntax would be: “如果您要导入类路径之外的资源,则语法为:

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

" "

In my case I just needed to do:就我而言,我只需要这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM