JoshKni8
JoshKni8

Reputation: 155

How to reference bean property values?

Here's what I am trying to do. I have a spring batch job which triggers a bean with multiple properties. I want these properties to be divided into separate beans for organizational purposes.

So I currently have this:

<bean id="runSQL" class="Tasklet"
    scope="step">
    <property name="sourceSQL"
        value="SQL STATEMENT HERE" />
    <property name="targetSQL"
        value="SQL STATEMENT HERE"></property>

  <property name="filePath" value="#{jobParameters['OUTPUT.FILE.PATH']}"> </property>
</bean>

but I basically want this (not working due to lack of class definition and I don't know if #{souce.sourceSQL} is a valid way of grabbing bean properties):

<bean id="runSQL" class="Tasklet"
    scope="step">
    <property name="sourceSQL"
        value="#{source.sourceSQL}" />
    <property name="targetSQL"
        value="#{target.targetSQL}"></property>

  <property name="filePath" value="#{jobParameters['OUTPUT.FILE.PATH']}">     </property>
</bean>

<bean id="sourceSQL" class="Class not needed"
    scope="step">
    <property name="sourceSQL"
        value="SQL STATEMENT HERE" />
    </property>
</bean>

<bean id="targetSQL" class="Class not needed"
    scope="step">
    <property name="sourceSQL"
        value="SQL STATEMENT HERE" />
    </property>
</bean>

I have tried to reference the beans traditionally with

<ref bean="someBean"/>

but my Tasklet isn't designed to receive a bean, just the property values and I would prefer to leave the Tasklet as is. How do I get around this or alternative ways of storing this data for the beans?

Upvotes: 1

Views: 1915

Answers (1)

sh0rug0ru
sh0rug0ru

Reputation: 1626

You're on the right track with #{...}. If you want to reference a bean, stick a @ in front of the Spring bean ID, for example #{@sourceSQL.sourceSQL} and #{@targetSQL.sourceSQL}.

See the documentation for the Spring Expression language.

Upvotes: 1

Related Questions