1 dependencies required with MAVEN import (under Project tab)
<Properties> <spring_version>3.2.2.RELEASE</spring_version> </Properties> <!--Spring Dependent - <Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-core</Artifactid> <version>${spring_version}</version> </Dependency> <Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-beans</Artifactid> <version>${spring_version}</version> </Dependency> <Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-tx</Artifactid> <version>${spring_version}</version> </Dependency> <Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-aop</Artifactid> <version>${spring_version}</version> </Dependency> <Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-context</Artifactid> <version>${spring_version}</version> </Dependency> <Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-context-support</Artifactid> <version>${spring_version}</version> </Dependency> <Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-web</Artifactid> <version>${spring_version}</version> </Dependency> <Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-webmvc</Artifactid> <version>${spring_version}</version> </Dependency> <Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-orm</Artifactid> <version>${spring_version}</version> </Dependency> <Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-test</Artifactid> <version>${spring_version}</version> </Dependency> <Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-jdbc</Artifactid> <version>${spring_version}</version> </Dependency> </Dependencies>
2 Creating a Test bean
PackageBean;/*** Created by computer on 2017/9/12.*/ Public classStudent { PublicString ID; PublicString name; PublicString intro; PublicString getId () {returnID; } PublicString GetName () {returnname; } PublicString Getintro () {returnintro; } Public voidsetId (String id) { This. ID =ID; } Public voidsetName (String name) { This. Name =name; } Public voidSetintro (String intro) { This. Intro =intro; } Public voideat () {System.out.println ("Students eat"); }}
3 Creating Spring.xml
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "http// Www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd "> Class= "Bean. Student "></bean></beans>
4 Testing
Packagetest;ImportBean. Student;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.context.support.FileSystemXmlApplicationContext;/*** Created by computer on 2017/9/12.*/ Public classTest { Public Static voidMain (string[] args) {ApplicationContext ApplicationContext=NewFilesystemxmlapplicationcontext ("Classpath:spring.xml"); Student Student= (Student) applicationcontext.getbean ("Student"); Student.eat (); }}
Control Desk
Project directory Structure
Spring Environment Setup (simple example)