Spring IOC using @autowire annotation- java configuration

  • @Autowired annotation – We can use Spring @Autowired annotation for spring bean autowiring.

  • @Autowired annotation can be applied on variables and methods for autowiring byType.

  • We can also use @Autowired annotation on constructor for constructor based spring autowiring.

  • For @Autowired annotation to work, we also need to enable annotation based configuration in spring bean configuration file.

  • This can be done by context:annotation-config element

To implement this we do not need setter method of address.

Remove setter of address from student.

Use autowire like this. Student and spconfig.xml will look like this.



Need guided training for this topic?

Learn with mentors, projects, mock interviews, and placement support at The Kiran Academy.

Explore Courses Book Free Demo