In this tutorial you will see an example of spring autowiring byName. The Autowiring is done by property name.
Student.java
package spring.noautowiring.mode;
|
College.java
|
package spring.noautowiring.mode; import org.springframework.beans.factory.annotation.Autowired; public class College { private Student student; private String registration; private String year; @Autowired public void setStudent(Student student) { this.student = student; } public String getRegistration() { return registration; } public void setRegistration(String registration) { this.registration = registration; } public String getYear() { return year; } public void setYear(String year) { this.year = year; } @Override public String toString() { return "College [registration=" + registration + ", Student=" + student + ",year=" + year + "]"; } } |
AutowireMain.java
package spring.noautowiring.mode;
|
context.xml
<beans xmlns="http://www.springframework.org/schema/beans"
|
| College [registration=BL001, Student=Student [name=Raj, age=22,address=Delhi],year=2001] |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.