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.



Ready for structured training?

Learn Java Full Stack with real projects

Live classes, practical projects, interview preparation and placement support in one guided programme.

View Java Full Stack Course Book Free Demo