问题描述
我已经在使用spring-batch和spring-boot的项目中工作.
I have worked on a project using spring-batch and spring-boot.
我遵循确切的规则,如何通过以下方式将其集成:1.删除所有@EnableBatchProcessing2.添加ServletConfiguration和WebappConfiguration(并使用
I followed the exact rules how to integrate it by:1. removing all @EnableBatchProcessing2. adding ServletConfiguration and WebappConfiguration (and also import them using
@Import({ ServletConfiguration.class, WebappConfiguration.class })
-
添加道具:
add props:
batch-mysql.properties
batch-mysql.properties
business-schema-mysql
business-schema-mysql
并修改具有以下内容的application.properties:
and modified application.properties with:
server.servletPath=/*
spring.freemarker.checkTemplateLocation=false
ENVIRONMENT=mysql
现在这是副作用.我的应用除了Java配置外,还使用了applicationContext .xml.
Now here is the side effect. My app is using an applicationContext .xml in addition to it's java config.
那个applicationContext有一些占位符:
that applicationContext has some place holders:
<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
后,我立即收到此错误:
As soon as I integrated spring-batch-admin
I got this error:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'serviceId' in string value "${serviceId}"
at
...
我尝试了@PropertySource导入它,但是没有用:
I tried @PropertySource to import it, but it didn't work:
@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
后,我就设法附加了这些道具.
As soon as I removed spring-batch-admin
from my spring-boot
project I manage to attach those props.
有什么办法解决这个问题吗?
Any idea how to overcome this?
推荐答案
您可以覆盖spring-batch-admin
默认上下文加载配置.在src/main/resources/META-INF/spring/batch/override/manager/
中,您可以将env-context.xml
文件放置在需要加载资源的配置中.
You can override spring-batch-admin
default context loading configuration. In src/main/resources/META-INF/spring/batch/override/manager/
you can place env-context.xml
file with configuration of resources which need to be loaded.
这里是 spring batch admin 可以用作起点,因此您可以执行以下操作:
Here is spring batch admin one which can be used as starting point so you can do something like:
<?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-batch-admin集成到现有的Spring Boot中后无法导入属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!