我曾参与过一个使用 spring-batch 和 spring-boot 的项目。
我遵循了如何集成它的确切规则: 1.删除所有@EnableBatchProcessing 2.添加ServletConfiguration和WebappConfiguration(并使用导入它们
@Import({ ServletConfiguration.class, WebappConfiguration.class })
添加 Prop :
batch-mysql.properties
业务架构-mysql
并修改了 application.properties:
server.servletPath=/*
spring.freemarker.checkTemplateLocation=false
ENVIRONMENT=mysql
现在这是副作用。除了 java 配置之外,我的应用程序还使用 applicationContext .xml。
applicationContext 有一些占位符:
<context:property-placeholder
location="file:///etc/location/services/myapp.properties"/>
<bean name="configuration" class="com.mycompany.commons.configuration.factory.BeanAwareConfigurationFactory">
<property name="serviceId" value="${serviceId}"/>
...
</bean>
集成 spring-batch-admin
后,我收到此错误:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'serviceId' in string value "${serviceId}"
at
...
我尝试使用@PropertySource导入它,但没有成功:
@PropertySource("file:///etc/location/services/myapp.properties")
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
System.out.printf("Started processor service app");
}
当我从 spring-boot
项目中删除 spring-batch-admin
后,我就设法附加这些 Prop 。
知道如何克服这个问题吗?
最佳答案
您可以覆盖spring-batch-admin
默认上下文加载配置。在 src/main/resources/META-INF/spring/batch/override/manager/中,您可以放置 env-context.xml 文件,其中包含需要配置的资源已加载。
这里是spring batch admin可以用作起点,这样您就可以执行以下操作:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- Use this to set additional properties on beans at run time -->
<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>
<!-- this line you can add-->
<value>file:///etc/location/services/myapp.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>
</beans>
关于spring - 将 spring-batch-admin 集成到现有的 spring boot 后无法导入属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29195981/