//Bean.java
public class SampleBean{
private String message;
public void setMessage(String message){
this.message=message; //setter injection
}
public void ShowMessage(){
system.out.println("Message"+message);
}
}
//Main.java
Class Main{
public Static Void Main(String args[]){
//启动ApplicationContext容器
ApplicationContext applicationcontext = new ClassPathXmlApplicationCOntext("Spring.xml");
//To Read the SampleBean
Object o=applicationcontext .getBean("SampleBean");
SampleBean sampleBean=(SampleBean)o;
//Invoke the Method
sampleBean.ShowMessage();
}
}
//Spring.Xml
// 您需要配置一些 Spring 和 Xml 所需的更多命名空间
<bean id="sampleBean" class="SampleBean">
<property name="message" value="this is the use of property Tag"/>
</bean>
//output :This is the use or Property Tag
explanation: when we want to perform Setter Injection we go for the Property
Tag
In spring we have some dependency injections like setter,constructor,interface,lookup method injection
when we use the Setter Injection first Dependent class object is create and next the dependency class object is created