Java 具有资源值的SpringJUnit4ClassRunner上下文配置
我正在尝试配置Spring、Junit和Hibernate(为我们的测试用例启用Java 具有资源值的SpringJUnit4ClassRunner上下文配置,java,spring,junit-runner,spring-boot-test,Java,Spring,Junit Runner,Spring Boot Test,我正在尝试配置Spring、Junit和Hibernate(为我们的测试用例启用@Autowire注释)。我当前的设置是: @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration({ "file:src/main/webapp/WEB-INF/applicationContext.xml", "file:src/main/webapp/WEB-INF/di
@Autowire
注释)。我当前的设置是:
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration({
"file:src/main/webapp/WEB-INF/applicationContext.xml",
"file:src/main/webapp/WEB-INF/dispatcher-servlet.xml",
})
public class UserManagementServiceTest {...}
但是,初始化失败,原因是
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
我们在context.xml
文件中定义了各种凭证,这些凭证是tomcat在运行应用程序时获取的。结构如下
<Context>
<Resource name="abc/abcManager"
auth="Container"
type="path.to.file"
factory="org.apache.naming.factory.BeanFactory"
attr1="asas"
attr2="asda"/>
</Context>
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.xml.sax.SAXParseException; lineNumber: 19; columnNumber: 10; cvc-elt.1: Cannot find the declaration of element 'Context'.