其他分享
首页 > 其他分享> > 将spring-batch-admin集成到现有的spring boot后,无法导入属性

将spring-batch-admin集成到现有的spring boot后,无法导入属性

作者:互联网

我使用弹簧批和弹簧靴进行了一个项目.

我按照确切的规则如何通过以下方式集成它:
1.删​​除所有@EnableBatchProcessing
2.添加ServletConfiguration和WebappConfiguration(并使用它们导入它们

@Import({ ServletConfiguration.class, WebappConfiguration.class })

>添加道具:

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,我就设法附加这些道具.

知道怎么克服这个吗?

解决方法:

您可以覆盖spring-batch-admindefault上下文加载配置.在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,spring-batch-admin
来源: https://codeday.me/bug/20190609/1205521.html