assume I have that class
public Student{
private String name;
private Address address;
public Student(String fName, Address address){
name = fname;
this.address = address;
}
I defined this class within Spring configuration as
<bean name="studentInstance" class="StackOverFlow.Student"/>
now i'd like to use getBean with parameter I will pass to constructor.
equal to Student s = new Student(name,address)
I know Spring supplies a methond getBean(class_name,parms....)
however I dont know how I should config Spring.xml configuration file.
I would like to avoid using Setter and getter in order to fill a new bean.
I found lots of example of how to define </constructor-arg>
within the xml but each time it was with default values. here I let the user to enter different values for each object.
I'd like to use
ApplicationContext context = new ClassPathXmlApplicationContext(Spring.xml file path);
Student s= (Student)context.getBean("studentInstance",name,address);
I need help with the configuration file only
Thanks in Advance!!
I already checked those links : Link1 Link2 Link3 Link4
~~~~~Edit ~~~~~~~
Solved! constructor-injection is not needed here I just added prototype scope to my bean as shown below.
<bean name="carInstance" class="MainApp.bl.GasStation.Car" scope="prototype"/>