测试类测试的时候发生了这个错误
java.lang.IllegalStateException: Failed to load ApplicationContext
原因是没有加载Spring的配置,这时候可以查看web.xml中是否加载了Spring的配置
<!--配置DispatcherServlet拦截 -->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--dispatcherServlet对应的上下文,默认位置是/WEB-INF/$servlet-name$-servlet.xml -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-*.xml</param-value><!--表示加载Spring文件下以Spring-开头的所有xml文件-->
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
如果加载了,在查看你的测试类中是否加载了Spring文件
@ContextConfiguration(locations = {"classpath:spring/spring-applicationContext.xml", "classpath:spring/spring-config.xml"})
表示我的测试类需要加载这俩个测试文件,也可以和下面一样加载Spring中所有以Spring-开头的的配置文件
@ContextConfiguration(locations = {"classpath:spring/spring-*.xml"})