Java Series Spring Learning--spring build (I.)

Source: Internet
Author: User
Tags aop

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> &LT;NAME&GT;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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.