I have worked on a project using spring-batch and spring-boot.
I followed the exact rules how to integrate it by:
1. removing all @EnableBatchProcessing
2. adding ServletConfiguration and WebappConfiguration (and also import them using
@Import({ ServletConfiguration.class, WebappConfiguration.class })
add props:
batch-mysql.properties
business-schema-mysql
and modified application.properties with:
server.servletPath=/*
spring.freemarker.checkTemplateLocation=false
ENVIRONMENT=mysql
Now here is the side effect. My app is using an applicationContext .xml in addition to it's java config.
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>
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
...
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");
}
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?
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.
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>
I forked the github project and I added the fix to prevent the placeholder error. You can get the new code here: https://github.com/vesperaba/spring-batch-admin-spring-boot.
The issue was SpringBatch has it's own PropertyPlaceholder and you have to overwrite it but to do that you have to manually import some files in order to avoid the one define it.
Here you can find the new conf: https://github.com/vesperaba/spring-batch-admin-spring-boot/blob/master/src/main/java/de/codecentric/batch/config/MainV2Configuration.java