Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring constructor params?

Tags:

java

spring

Some of my classes have final fields that are populated from the constructor as well as properties that can be assigned from getters and setters.

If I can do this using spring, what does the springcontext.xml file look like that creates objects in this way?

Thank you

like image 806
Allain Lalonde Avatar asked Jan 24 '23 21:01

Allain Lalonde


2 Answers

<bean id="testWithConstructorArg"
        class="com.Test">
        <constructor-arg ref="referencingSomething"/>
</bean>

more: http://www.javalobby.org/java/forums/t18396.html

like image 127
Simon Groenewolt Avatar answered Jan 31 '23 15:01

Simon Groenewolt


<bean id="myBean" class ="com.example.MyClass">
<constructor-arg type="java.lang.String">
<value>hello world</value>
</constructor-arg>
</bean>

then you can have the normal setter/getter based <paramater name="blah" value="whatever"/> as usual.

like image 33
simonlord Avatar answered Jan 31 '23 17:01

simonlord