一、新建maven项目
二、引入spring jar包
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
wjxiaoqiao
wj
war
0.0.1-SNAPSHOT
wj Maven Webapp
http://maven.apache.org
org.springframework
spring-context
5.0.2.RELEASE
javax.servlet
javax.servlet-api
4.0.0
provided
junit
junit
3.8.1
test
wj
三、编写配置文件
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
">
四、测试类
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();
}
}
五、测试是否成功