Spring Web Service Tests: java.lang.IllegalStateExcepton: Failed to load application context

I get the error "java.lang.IllegalStateExcepton: Could not load application context" when I try to run my unit test from Eclipse.

The unit test itself seems very simple:

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);
    }
}

But no matter what I do with @ContextConfiguration, I still get the same error.

The applicationContext.xml file is located in the / etc / ws folder, but even if I put the copy in the same folder, it still gives me errors.

I am very new to Java, Spring, Eclipse, and Ant, and really don't know where this is going.

+3
source share
1 answer

, @ContextConfiguration. , applicationContext.xml (, , , , /etc/ws ). :

  • @ContextConfiguration(locations={"/etc/ws/applicationContext.xml"})
  • applicationContext.xml (, WEB-INF) @ContextConfiguration(locations={"classpath:applicationContext.xml"})

2 , , applicationContext.xml, . Eclipse .

+6

Source: https://habr.com/ru/post/1724477/


All Articles