【问题标题】:Java Spring batch access command line arguments in XML and Java Annotation configXML 和 Java Annotation 配置中的 Java Spring 批处理访问命令行参数
【发布时间】:2018-10-01 06:48:38
【问题描述】:

如何使用 spring 获取 xml 配置文件中的命令行参数?

使用属性文件我可以这样写:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:batch="http://www.springframework.org/schema/batch"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-3.0.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:property-placeholder location="file:///my.property" /> 

    <bean id="mybean">
      <property name="prop1" ref="#{jobParameters['value.from.property']}" />
    </bean>

    <bean id="mybean2">
      <property name="prop1" ref="#{jobParameters['value2.from.property']}" />
    </bean>

    <bean id="mybean3">
      <property name="prop1" ref="#{jobParameters['value3.from.property']}" />
    </bean>
    <import resource="classpath:/META-INF/spring/module-context.xml" />

</beans>

但是我如何解释 Spring 从命令行参数而不是属性占位符中指定的属性文件获取值?

谢谢

【问题讨论】:

标签: spring spring-batch java-annotations


【解决方案1】:

要从属性文件中读取,请使用

<property name="prop1" value="${value.from.property}" />

从作业参数中读取使用

<property name="prop1" value="#{jobParameters['value.from.jobParameter']}" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-27
    • 2018-05-07
    • 2010-09-13
    • 2016-04-21
    • 2021-02-13
    • 2018-03-08
    • 2016-08-10
    • 1970-01-01
    相关资源
    最近更新 更多