SpringWeb服务单元测试:java.lang.IllegalStateExcepton:未能加载应用程序上下文
当我试图从Eclipse中运行单元测试时,我收到错误“java.lang.IllegalStateExcepton:未能加载应用程序上下文” 单元测试本身似乎非常简单:SpringWeb服务单元测试:java.lang.IllegalStateExcepton:未能加载应用程序上下文,java,spring,junit,Java,Spring,Junit,当我试图从Eclipse中运行单元测试时,我收到错误“java.lang.IllegalStateExcepton:未能加载应用程序上下文” 单元测试本身似乎非常简单: package com.mycompany.interactive.cs.isales.ispr.ws.productupgrade; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.spri
package com.mycompany.interactive.cs.isales.ispr.ws.productupgrade;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/applicationContext.xml"})
public class ProductUpgradeTest {
@Test
public void getProductUpgrade () throws Exception
{
//System.out.println(PrintClasspath.getClasspathAsString());
Assert.assertTrue(true);
}
}
但是无论我对@ContextConfiguration
做了什么,我仍然会得到相同的错误
applicationContext.xml文件驻留在/etc/ws文件夹中,但即使我将副本放在同一文件夹中,它仍然会给我带来错误
我对Java、Spring、Eclipse和Ant非常陌生,真的不知道哪里出了问题。问题是在
@ContextConfiguration
注释中使用了绝对路径。现在您可以指定applicationContext.xml位于系统的根文件夹中(可能不是,因为您说它位于/etc/ws)。我认为有两种可能的解决办法:
@ContextConfiguration(locations={”/etc/ws/applicationContext.xml})
@ContextConfiguration(locations={“classpath:applicationContext.xml”})