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

2023-12-02

我曾经做过一个使用 spring-batch 和 spring-boot 的项目。

我遵循了如何集成它的确切规则: 1.删​​除所有@EnableBatchProcessing 2.添加ServletConfiguration和WebappConfiguration(并使用导入它们

@Import({ ServletConfiguration.class, WebappConfiguration.class })
  1. 添加道具:

    批处理-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-batch-admin从我的spring-boot我设法附加这些道具的项目。

知道如何克服这个问题吗?


您可以覆盖spring-batch-admin默认上下文加载配置。在src/main/resources/META-INF/spring/batch/override/manager/你可以放置env-context.xml包含需要加载的资源配置的文件。

Here is 春季批次管理可以用作起点,这样您就可以执行以下操作:

<?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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 spring-batch-admin 集成到现有的 spring boot 后无法导入属性 的相关文章

随机推荐