2009-12-02 4 views
3

Eclipse에서 유닛 테스트를 실행하려고 할 때 "java.lang.IllegalStateExcepton : 어플리케이션 컨텍스트로드 실패"오류가 발생합니다. .스프링 웹 서비스 유닛 테스트 : 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.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에 매우 익숙하며, 이것이 어디에서 잘못 될지 정말로 알지 못합니다.

답변

6

@ContextConfiguration 주석에 절대 경로를 사용하는 것이 문제입니다. applicationContext.xml이 시스템의 루트 폴더에 있다고 지정합니다 (/ etc/ws에 있다고 말하기 때문에 그렇지 않은 경우). 나는 두 가지 솔루션을 참조하십시오

  1. 사용 @ContextConfiguration(locations={"/etc/ws/applicationContext.xml"}) (당신의 WEB-INF 폴더에, 예를 들어) 프로젝트로 applicationContext.xml 파일을 이동 한 경우에는 2 년 @ContextConfiguration(locations={"classpath:applicationContext.xml"})

를 사용

  • , 당신 applicationContext.xml을 배치 할 디렉토리가 클래스 경로에 있는지 확인해야합니다. 이클립스에서는 프로젝트 속성에서 구성 할 수 있습니다.