Spring Core- Create bean(POJO) using setter Method

Posted on Updated on

The very common method to create a bean in Spring framework is to inject via setter method. The below example shows how to use setter method to create a bean.

1) School.java

We have a School bean which contain name and noOfFaculties as instance variables.

2) Spring Configuration

We have created a bean with name school having class attribute pointing to the java class.

Value for instance variables name and noOfFaculties have been injected through property tag.

3) Load bean xml and run the program

4) Output:

Name : Code2Succeed
No of Faculties : 100

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.