繁体   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