Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set default argument value when using Spring constructor injection

 
Jonilie Echavez
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Is it possible to set a default value for constructor arguments when using Spring constructor injection?

Here is my xml file where i define the argument values for the class SupplierImpl. It looks up the values from a properties file.

healthopts.spring.xml:
--------------------------------
<bean id="supplier" class="com.healthopts.dao.supply.SupplierImpl">
<constructor-arg index="0"><value>${supplier.sourceLocator}</value></constructor-arg>
<constructor-arg index="1"><value>${supplier.reloadInterval}</value></constructor-arg>
</bean>

Here is the properties file that is used to look up for the values to be passed in healthopts.spring.xml

healthopts.properties:
---------------------------------
supplier.sourceLocator=/home/adminOpt/healthops/supplier.doc
supplier.reloadInterval=3600000

Somewhere i have also already defined PropertyPlaceholderConfigurer that "healthopts.properties" is the name of the properties file to get the values from.

However, suppose the key called "supplier.reloadInterval" is not found in the properties file, is there a way to configure from my healthopts.spring.xml a default value for this argument?

Appreciate your help.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic