将spring-batch-admin集成到现有的Spring Boot中后无法导入属性 [英] Can't Import properties after integrating spring-batch-admin into existed spring boot

查看:59
本文介绍了将spring-batch-admin集成到现有的Spring Boot中后无法导入属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在使用spring-batch和spring-boot的项目中工作.

I have worked on a project using spring-batch and spring-boot.

我遵循确切的规则,如何通过以下方式将其集成: 1.删​​除所有@EnableBatchProcessing 2.添加ServletConfiguration和WebappConfiguration(并使用

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 })

  1. 添加道具:

  1. 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-admindefault 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>

这篇关于将spring-batch-admin集成到现有的Spring Boot中后无法导入属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆