Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

How to set default argument value when using Spring constructor injection

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic