1. Create a MAVEN project, project name springdemo35,
650) this.width=650; "src=" https://s1.51cto.com/wyfs02/M00/8F/22/wKioL1jUxL6hrH4bAAA-J3nE7vs344.png-wh_500x0-wm_ 3-wmp_4-s_3086935474.png "title=" qq20170324150239.png "alt=" wkiol1juxl6hrh4baaa-j3ne7vs344.png-wh_50 "/>
2. Configure maven, Modify the Pom.xml file in the project, modify the content as follows
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance " xsi:schemalocation=" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ Xsd/maven-4.0.0.xsd "> <modelVersion>1.0.0</modelVersion> <groupId> Shequ</groupid> <artifactid>springdemo13</artifactid> <version> 0.0.1-snapshot</version> <properties> <java.version>1.7 </java.version> <project.build.sourceencoding>utf-8</project.build.sourceencoding > <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> <repositories> <repository> <id>codelds</id> <url>https://code.lds.org/nexus/content/groups/main-repo </url> </repository&gT; </repositories> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> </dependency> <dependency > <groupid>org.springframework</groupid> <artifactid>spring-core </artifactId> <version>4.1.4.RELEASE</version> </dependency> <dependency> <groupId> Org.springframework</groupid> <artifactid> Spring-context</artifactid> <version>4.1.4.release </version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactId>spring-jdbc</artifactId> <version>4.1.4.RELEASE</version> </dependency> <dependency> < Groupid>mysql</groupid> <artifactid> mysql-connector-java</artifactid> <version>5.1.34 </version> </dependency> </dependencies> <build/></project>
3. Create the entity Bean Forum, package name (com.mycompany.shequ.bean) under Src/main/java
650) this.width=650; "src=" https://s5.51cto.com/wyfs02/M00/8F/22/wKioL1jUxPLwjo0FAABIWRXzeKE172.png-wh_500x0-wm_ 3-wmp_4-s_179930178.png "title=" qq20170324150330.png "alt=" wkiol1juxplwjo0faabiwrxzeke172.png-wh_50 "/>
4. Entity Bean Forum content is as follows
Package Com.mycompany.shequ.bean;public class Forum {private int fid;private String name;private int displayorder;public int Getdisplayorder () {return displayorder;} public void Setdisplayorder (int displayorder) {this.displayorder = displayorder;} public int Getfid () {return fid;} public void Setfid (int fid) {this.fid = fid;} Public String getName () {return name;} public void SetName (String Name) {this.name = name;} @Overridepublic String toString () {return "{fid=>" +this.fid+ ",name=>" +this.name+ ",displayorder=>" + this.displayorder+ "}";}}
5. Under src/main/resource, Create the Bean profile spring-bean.xml,
650) this.width=650; "src=" https://s3.51cto.com/wyfs02/M01/8F/24/wKiom1jUxUawWtHRAABJqDuXvac635.png-wh_500x0-wm_ 3-wmp_4-s_3929455647.png "title=" qq20170324150454.png "alt=" wkiom1juxuawwthraabjqduxvac635.png-wh_50 "/>
6. The contents of the configuration file Spring-bean.xml are as follows
<beans xmlns= "http://www.springframework.org/schema/beans" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "xmlns:p=" http://www.springframework.org/schema/p "xmlns:util=" http://www.springframework.org /schema/util "xsi:schemalocation=" http://www.springframework.org/schema/beanshttp://www.springframework.org/ schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/utilhttp://www.springframework.org/ Schema/util/spring-util-4.0.xsd "><bean id=" basebean "class=" com.mycompany.shequ.bean.Forum ">< Property name= "displayorder" value= "1" ></property></bean><bean id= "forumbean" parent= "baseBean" ><property name= "fid" value= "1" ></property><property name= "name" value= "inherit The configuration of the parent bean" ></ Property></bean></beans>
7. Under src/main/resource, Create the core configuration file applicationcontext.xml,
650) this.width=650; "src=" https://s4.51cto.com/wyfs02/M00/8F/25/wKiom1jUxami7dxPAABFzjIEnMA706.png-wh_500x0-wm_ 3-wmp_4-s_2554287503.png "title=" qq20170324150634.png "alt=" wkiom1juxami7dxpaabfzjienma706.png-wh_50 "/>
8. The content of the core configuration file Applicationcontext.xml is as follows
<beans xmlns= "http://www.springframework.org/schema/beans" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "xsi:schemalocation=" http://www.springframework.org/schema/beanshttp:// Www.springframework.org/schema/beans/spring-beans-4.0.xsd "><import resource=" bean/spring-bean.xml "/> </beans>
9. Create a test file under Src/test/java apptest, package name (com.mycompany.shequ.test)
650) this.width=650; "src=" https://s1.51cto.com/wyfs02/M02/8F/22/wKioL1jUxe3BF-SbAABIZkOaIO8976.png-wh_500x0-wm_ 3-wmp_4-s_669630299.png "title=" qq20170324150742.png "alt=" wkiol1juxe3bf-sbaabizkoaio8976.png-wh_50 "/>
10. The contents of the test file apptest are as follows
Package Com.mycompany.shequ.test;import Org.junit.test;import org.springframework.context.ApplicationContext; Import Org.springframework.context.support.classpathxmlapplicationcontext;import com.mycompany.shequ.bean.Forum; public class apptest {@Testpublic void beantest () {applicationcontext context = new Classpathxmlapplicationcontext ("app Licationcontext.xml "); Forum Forum = (forum) Context.getbean ("forumbean"); System.out.println (forum);}}
11. Right-click on the Beantest method of the test class apptest and output the result
650) this.width=650; "src=" https://s4.51cto.com/wyfs02/M00/8F/23/wKioL1jUxi7TiXAwAAEN0p3QxZ0793.png-wh_500x0-wm_ 3-wmp_4-s_121297333.png "title=" qq20170324150846.png "alt=" wkiol1juxi7tixawaaen0p3qxz0793.png-wh_50 "/>
650) this.width=650; "src=" https://s5.51cto.com/wyfs02/M02/8F/23/wKioL1jUxlbjrXsIAABwCKMO5XE548.png-wh_500x0-wm_ 3-wmp_4-s_879507396.png "title=" qq20170324102905.png "alt=" wkiol1juxlbjrxsiaabwckmo5xe548.png-wh_50 "/>
This article from the "vegetarian yan" blog, declined to reprint!
Inheritance of Spring4-bean