This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes How to set default argument value when using Spring constructor injection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to set default argument value when using Spring constructor injection" Watch "How to set default argument value when using Spring constructor injection" New topic
Author

How to set default argument value when using Spring constructor injection

Jonilie Echavez
Greenhorn

Joined: Jun 26, 2009
Posts: 20
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.
 
subject: How to set default argument value when using Spring constructor injection
 
Similar Threads
[Spring Security] No bean named 'springSecurityFilterChain' is defined
read properties in my java application defined in spring bean "PropertyPlaceholderConfigurer"
Sring - Configuring mailing
Dependency checking and constructor injection
Spring config files inside jar