Friday, December 18, 2009

Spring : Create instance with constructor arguments

If our java class has a constructor like this with argument.

public class Home() {
    private String name;

    public Home(String s) {
         name = s;   
    }
}

We can write our spring bean like this.

       <bean id="home1" class="<class.path>.Home">
           <constructor-arg value="My_Home"/>
       </bean>