Neither GenericXmlContextLoader nor AnnotationConfigContextLoader was able to detect defaults

来源:互联网 发布:淘宝 购物 编辑:程序博客网 时间:2024/06/05 13:24

今天使用spring TestContext测试spring应用程序时,发现上述错误,经过多次检查,发现UserManagerImplTest-context.xml的位置不对,必须将该文件放置在测试文件同一个包中,而且名字必须是 ” 测试类名-context.xml".且文件内容指定为

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<import resource="classpath:beans.xml"/> 

</beans>

其中classpath:表示指定spring的配置文件在classpath的位置。

除此之外,该测试类上必须指明@ContextConfiguration,属性注入时在属性上指明@resource或者@Autowired,测试方法指明@test

0 0
原创粉丝点击