Tuesday 15 February 2011

Spring Web Service Unit Tests: java.lang.IllegalStateExcepton: Failed to load Application Context -


"itemprop =" text ">

I'm getting the error" java.lang.IllegalStateExcepton: Failed to load the application context "when I run my unit I'm trying to Testing from inside the eclipse

The unit looks very simple in the test:

  package com.mycompany.interactive.cs.isales.ispr.ws.productupgrade; Import org.junit.assert; Import org.junit.Test; Import org.junit.runner.RunWith; Import organization Source: 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 start doing with , @ContextConfiguration .

applicationContext.xml I still get the same error file is within a folder / etc / ws, but even if I put a copy in the same folder, it's still me errors is.

I am very new to Java, Spring, Eclipse and Ant, and in fact it is not known why this is going wrong.

The problem is that you specify your @ContextConfiguration annotation now That your applicationContext.xml is located in the root folder of your system (where this is probably not, because you say it is on / etc / ws). I see two possible solutions:

  1. Use @ContextConfiguration (locations = { "/ etc / ws / applicationContext.xml"})
  2. move your project (your applicationContext.xml file for example) in your WEB-INF folder and using @ContextConfiguration (locations = { "classpath: applicationContext.xml"})

If in 2, you will need to make sure that the directory in which you place your application is located in your classpath. This can be configured in your project property in Eclipse.


No comments:

Post a Comment