Spring MVC 测试加载 xml fie 时出错
我的代码可以工作,但在以下行的 Junit 模拟测试中失败。
ApplicationContext ctx = new ClassPathXmlApplicationContext("../MyFile.xml");
我该如何解决这个问题?
添加@ContextConfiguration还是有其他方法?
“ApplicationContext ctx = new ClassPathXmlApplicationContext(“../MyFile.xml”);”这行代码在普通方法中不在测试类中
My Code is works, but it fail in Junit mock testing in the below line.
ApplicationContext ctx = new ClassPathXmlApplicationContext("../MyFile.xml");
HOw do I fix this?
adding @ContextConfiguration or is there another way?
"ApplicationContext ctx = new ClassPathXmlApplicationContext("../MyFile.xml");" This line is in the normal method not in the test class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你的问题到底是什么,因为你已经提到了这两种解决方案,但是当然你可以选择通过注释将其放在测试类上
或通过用 @BeforeClass 注释的方法初始化它,因此服务器仅启动一次在此类中的所有测试之前,如下例所示:
也许您需要解释初始化 ApplicationContext 时到底失败的原因。
I am not sure what your problem exactly is, since you already mentioned both solutions, but of course you can choose between either putting it on testclass by annotation with
or initializing it by method beeing annotated with @BeforeClass, so the server gets started just once before all tests in this class like the following example:
Maybe you need to explain what exactly fails when initialising your ApplicationContext.