spring1 (1)
spring1 (1)
spring1 (1)
Student.java
package spring1;
public class Student
{
private String name;
applicationContext.xml
package spring1;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class test
{
public static void main(String[] args)
{
Resource resource=newClassPathResource("applicationContext.xml");
BeanFactory factory=new XmlBeanFactory(resource);
Student student=(Student)factory.getBean("studentbean");
student.displayInfo();
}
}
OUTPUT
STEPS:
1 Create the bean class
Create a bean class which contains getters and setters method.
2 Create the xml file to provide the values for bean class
The bean element is used to define the bean for the given class.
The property element of bean specifies the property of the Student
class
The value specified in the property element will be set in the
Student class object
o org.springframework.core-3.0.1.RELEASE-A
o com.springsource.org.apache.commons.logging-1.1.1
o org.springframework.beans-3.0.1.RELEASE-A
Link: https://www.javatpoint.com/src/sp/spcorejars.zip
setter getter
XML
(applicationCont
ext.xml)