File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set default argument value when using Spring constructor injection
 
Similar Threads
Sring - Configuring mailing
Spring config files inside jar
Dependency checking and constructor injection
[Spring Security] No bean named 'springSecurityFilterChain' is defined
read properties in my java application defined in spring bean "PropertyPlaceholderConfigurer"