package examples;
public class ExampleBean {
// No. of years to the calculate the Ultimate Answer
private int years;
// The Answer to Life, the Universe, and Everything
private String ultimateAnswer;
public ExampleBean(int years, String ultimateAnswer) {
this.years = years;
this.ultimateAnswer = ultimateAnswer;
}
}
____________________________________________________________________________________
For the above case we can use the ‘type’ attribute incdating the argument type to avoid ambiguity.
____________________________________________________________________________________
<bean id="exampleBean" class="examples.ExampleBean">
<constructor-arg type="int" value="7500000"/><constructor-arg type="java.lang.String" value="42"/></bean>
_____________________________________________________________________________________
For the above same case we can also use the ‘index’ attribute to supply values to the constructor.
____________________________________________________________________________________
<bean id="exampleBean" class="examples.ExampleBean">
<constructor-arg index="0" value="7500000"/><constructor-arg index="1" value="42"/></bean>
____________________________________________________________________________________
No comments:
Post a Comment