Spring Setter Injection and Constructor Injection

In this post i am going to demonstrate you how to set bean property using spring setter injection and constructor. First i will demonstrate Happy scenario and later will be complex. This will force you to think deeply about bean.xml

Consider i have class User containing 3 property name,age and country. Using spring i want to display value of user with all it's property.

User.java
package com.anuj.spring.injection;
/**
 *
 * @author Anuj J Patel
 *
 */
public class User {

    private String name;
    private int age;
    private String country;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String toString()
    {
        String output = "Name : " + name + " Age: " + age + " Country:" + country;
        return output;
    }
}