1

我正在尝试配置 Spring、Junit 和 Hibernate(@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>

InitialContext然后使用类获取这些属性。

如何为我们的测试用例配置上述功能?

添加context.xml文件以ContextConfiguration给出错误

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'.
4

0 回答 0