The Idler
The Idler

Reputation: 124

Using Ternary operator to pass a parameter in spring configuration

I wish to know if there is a way of passing a parameter conditionally while defining a spring bean. More specifically, I am trying to create a util:map with two entries, the entries are dependent on system properties as defined below:

 <util:map id="queryParameterMap">
    <entry key="startDate" value="${startdate}"/>
    <entry key="endDate" value="${enddate}"/>
</util:map>

if the system parameter is not set, the value in the map should be defaulted to null. How can this be done? I have tried using spring expression language but that was not of much help.

Regards, Daya

Upvotes: 2

Views: 2414

Answers (2)

Bozho
Bozho

Reputation: 597046

PropertyPlaceholderConfigurer probably has the option to set unresolved properties to null. Apart from that, SpEL supports supports defaults. What have you tried?

Upvotes: 0

axtavt
axtavt

Reputation: 242686

Have you tried #{systemProperties['enddate']}? It does exactly what you want.

Upvotes: 2

Related Questions