0

How can I get the command line arguments in a xml configuration file with spring?

With property file I can write this:

<?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>

But how can I explain Spring to get the values from command line arguments instead of property file specified in property-placeholder?

Thanks

michele
  • 26,348
  • 30
  • 111
  • 168

1 Answers1

0

To read from property file use

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

To read from Job Parameter use

<property name="prop1" value="#{jobParameters['value.from.jobParameter']}" />
Sushil Behera
  • 817
  • 6
  • 20