First, the new MAVEN project
Second, the introduction of Spring jar Package
<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/maven-v4_0_0.xsd" > <modelversion >4.0.0</modelVersion> <groupId>wjxiaoqiao</groupId> <artifactId>wj</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <NAME>WJ Maven Webapp </name> <url>http://maven.apache.org</url> <dependencies> <!--https:// Mvnrepository.com/artifact/org.springframework/spring-context--><dependency> <groupId> Org.springframework</groupid> <artifactId>spring-context</artifactId> <version>5.0.2. Release</version></dependency> <!--https://mvnrepository.com/artifact/javax.servlet/ Javax.servlet-api--><dependency> <groupId>javax.servlet</groupId> <artifactId> javax.seRvlet-api</artifactid> <version>4.0.0</version> <scope>provided</scope></ dependency> <dependency> <groupId>junit</groupId> <artifactid>junit</artifact id> <version>3.8.1</version> <scope>test</scope> </dependency> </depende ncies> <build> <finalName>wj</finalName> </build></project>
Third, write the configuration file
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "http://www.springframework.org/schema/ Context " xsi:schemalocation=" Http://www.springframework.org/schema/beans/ http Www.springframework.org/schema/beans/spring-beans.xsd Http://www.springframework.org/schema/mvc http:/ /www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http ://www.springframework.org/schema/context/spring-context.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd "> <bean id=" test01 "class=" test.test01 "/> </beans>
Iv. Test class
Package Test;public class Test01 {public test01 () {System.out.println ("test01");} public void Prints () {System.out.println ("prints");}}
Package Test;import Java.io.ioexception;import Java.io.printwriter;import javax.servlet.servletexception;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Org.springframework.context.applicationcontext;import Org.springframework.context.support.classpathxmlapplicationcontext;public class Aservlet extends HttpServlet { public void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException { ApplicationContext context=new classpathxmlapplicationcontext ("Applicationcontext.xml"); test01 test01= (test01) Context.getbean ("test01"); Test01.prints ();}}
Five, the test is successful
Java Series Spring Learning--spring Build (i)