1、pom.xml文件引入spring-webmvc依赖,顺带加上junit做单元测试:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.18.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
2、引入spring配置文件:
名称为spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
</beans>
3、测试
public class TestCase {
private AbstractApplicationContext app;
@Before
public void before() {
app = new ClassPathXmlApplicationContext("classpath:spring.xml");
}
@After
public void after() {
app.close();
}
@Test
public void test() {
System.out.println(app);
}
}