spring-batch-admin的其他属性文件 [英] Additional properties files for spring-batch-admin
问题描述
我有一个使用spring-batch的Web应用程序,现在正在集成spring-batch-admin进行基本管理.
I have a web application using spring-batch and I'm now integrating spring-batch-admin for basic administration.
问题是作业配置文件(与现有应用程序的配置共享)使用我应用程序的类路径中文件的属性,但是spring-batch-admin的上下文无法加载它们.
The problem is that the jobs configuration files (which are shared with the configuration of the existing application) use properties from files in my application's classpath, but spring-batch-admin's context is not able to load them.
快速解决方案是覆盖placeholderProperties
The quick solution was to override the placeholderProperties
bean in spring-batch-admin just to add my properties files:
<bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/org/springframework/batch/admin/bootstrap/batch.properties</value>
<value>classpath:batch-default.properties</value>
<value>classpath:batch-${ENVIRONMENT:hsql}.properties</value>
<value>classpath:/path/to/jobs-config.properties</value> <!-- adding my properties here -->
</list>
</property>
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="false" />
<property name="order" value="1" />
</bean>
我不想将我的属性移动到spring-batch-admin的默认文件之一.有没有更简单的方法可以做到这一点?
I don't want to move my properties to one of spring-batch-admin's default files. Is there a simpler way to do this?
推荐答案
在这里回答我自己的问题...
Answering my own question here...
如文档所述,放置在META-INF/spring/batch/jobs/*.xml
下的配置文件由spring-batch-admin作为子上下文和父项的属性占位符加载(即
As described in the documentation, every job configuration file placed under META-INF/spring/batch/jobs/*.xml
is loaded by spring-batch-admin as a child context and property placeholders from the parent (i.e. this default bean) are inherited, but the child context can always create its own placeholder bean.
鉴于在我的情况下,作业配置文件与现有应用程序共享并使用应用程序类路径中的属性,解决方案是在META-INF/spring/batch/jobs/*.xml
中创建特定于spring-batch-admin的新作业文件:
Given that, in my case, the job configuration files are shared with an existing application and use properties from the application classpath, the solution is to create a new job file in META-INF/spring/batch/jobs/*.xml
specific for spring-batch-admin:
<!-- placeholder bean with additional properties for the child context -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/path/to/job-config.properties</value>
</list>
</property>
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="false" />
<property name="order" value="1" />
</bean>
<!-- external job configuration file is imported -->
<import resource="classpath*:/path/to/job.xml" />
这篇关于spring-batch-admin的其他属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!