Spring configuration file: Applicationcontext.xml
<?xml version= "1.0" encoding= "UTF-8"? ><beansxmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-3.1.xsd "><bean id=" student "class=" com.test.Student "><property name=" name "value=" Dalangge "/></bean></beans>
Entity class: Student.java
Package Com.test;public class Student {public string Name;public string GetName () {return name;} public void SetName (String name) {this.name = name;}}
Test class: Test.java
Package Com.test;import Org.springframework.context.applicationcontext;import Org.springframework.context.support.classpathxmlapplicationcontext;public class Test {/** * @param args */public static void Main (string[] args) {//TODO auto-generated method Stubapplicationcontext ct = new Classpathxmlapplicationcont Ext ("Applicationcontext.xml"); Student s = (Student) ct.getbean ("Student"); System.out.println (S.getname ());}}
Spring's Simple Demo