1. Create a MAVEN project, project name Springdemo36,
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/8F/25/wKiom1jUxzvCMFVVAABA_pJd59s468.png-wh_500x0-wm_ 3-wmp_4-s_1980469396.png "title=" Qq20170324151316.png "alt=" Wkiom1juxzvcmfvvaaba_pjd59s468.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/25/wKiom1jUx4zwIMipAABLCqMdJrU831.png-wh_500x0-wm_ 3-wmp_4-s_3517691531.png "title=" Qq20170324151436.png "alt=" Wkiom1jux4zwimipaablcqmdjru831.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://s1.51cto.com/wyfs02/M02/8F/25/wKiom1jUx86AUgnKAABNxDoiIrI518.png-wh_500x0-wm_ 3-wmp_4-s_3918923778.png "title=" Qq20170324151544.png "alt=" Wkiom1jux86augnkaabnxdoiiri518.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 "abstract=" true "><property name=" DisplayOrder " Value= "1" ></property></bean><bean id= "Forumbean" parent= "Basebean" class= " Com.mycompany.shequ.bean.Forum "><property name=" FID "value=" 1 "></property><property name=" name " Value= "Inherit abstract template" ></property></bean></beans>
7. Under Src/main/resource, create the core configuration file Applicationcontext.xml,
650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M02/8F/25/wKiom1jUyAjQqTwLAABG1HKIlxc232.png-wh_500x0-wm_ 3-wmp_4-s_922937416.png "title=" Qq20170324151640.png "alt=" Wkiom1juyajqqtwlaabg1hkilxc232.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://s5.51cto.com/wyfs02/M02/8F/26/wKiom1jUyEDTJJA0AABJpPXPnMA622.png-wh_500x0-wm_ 3-wmp_4-s_3700122458.png "title=" Qq20170324151734.png "alt=" Wkiom1juyedtjja0aabjppxpnma622.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/M01/8F/23/wKioL1jUyHKTKd-kAADvIqqZ0o0880.png-wh_500x0-wm_ 3-wmp_4-s_2670717907.png "title=" Qq20170324151827.png "alt=" Wkiol1juyhktkd-kaadviqqz0o0880.png-wh_50 "/>
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/8F/26/wKiom1jUyIGDvnocAABwCKMO5XE344.png-wh_500x0-wm_ 3-wmp_4-s_665830323.png "title=" Qq20170324102905.png "alt=" Wkiom1juyigdvnocaabwckmo5xe344.png-wh_50 "/>
This article from the "Vegetarian Yan" blog, declined to reprint!
spring4-Inheriting abstract templates