2013-03-03 6 views
0

저는 여기에서 꽤 새로워서 물어보고 싶지 않았지만 선택의 여지가없는 것 같습니다.Maven과 Spring : Maven이 내 리소스를 찾지 못했습니다.

필자는 자동화 테스트를 작성하고 있으며 얼마 전에 스프링과 Dependancy Injection과 그 모든 장점을 발견했습니다.

/src/test/java/automation/data 목록 :

@ContextConfiguration("classpath:/spring/surveyFlows.xml") 
public class SurveyDataProvider 
{ 

    @Autowired 
    private List<Survey> allSurveys; 

    public List<Survey> getAllSurveys() 
    { 
     return allSurveys; 
    } 
    public SurveyDataProvider() 
    { 
     TestContextManager testContextManager = new TestContextManager(getClass()); 
     try 
     { 
      testContextManager.prepareTestInstance(this); 
     } 
     catch (Exception e) 
     { 
      e.printStackTrace(); 
     } 
    } 
} 

나는 다음과 같이 (내 동료 중 하나가 이러한 사용에 동의하지만, 나는 이유를 이해하지 않습니다) 내 기본 데이터 공급자로 내 테스트에서 사용했습니다 그리고 물론 내 XML을 가지고 있어요 /src/test/resources/spring/. 노력,

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring/surveyFlows.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/surveyFlows.xml] cannot be opened because it does not exist

나는 주위를 둘러 보았다 시간 동안 모든 인터넷했습니다

재미있는 것은 이것이 내가 IntelliJ를 함께 실행하면 잘 작동하지만 maven 나를주고, 실행하는 그 빌어 먹을 오류를 거부한다는 것입니다 pom.xml 에 자원 디렉토리를 넣어 /src/main

    • 이동 자원 : 모든 종류의 것들

    ... 주사위가 없습니다.

    그래서 여기에 다소 달라 붙어 있습니다. 하드 코딩 된 매개 변수를 사용하여 이전 자바 스타일로 돌아갈 것을 진지하게 생각하고 있습니다. 누군가가 단서가있는 경우

    ...

  • +2

    'target/test-classes/spring'에서 파일을 찾을 수 있습니까? 퐁은 어떻게 생겼지? –

    +0

    그래, 거기에 XML을 참조하십시오,하지만 여전히 작동하지 않습니다 – jereshi

    +0

    나는 같은 문제가 있었고 비슷한 질문/대답 내 문제가 여기에 고정 : http://stackoverflow.com/questions/3571149/test-resources- 종속성이 아닌 클래스 패스 – kfox

    답변

    2

    이 무언가 우리를 위해 일했다. 대체 방법을 찾으면 알려줘.

    <build> 
        <!--Your other configuration --> 
    
        <testResources> 
         <!-- Not sure if including resource from main is needed --> 
         <testResource> 
          <directory>${project.basedir}/src/main/resources</directory> 
         </testResource> 
    
         <testResource> 
          <directory>${project.basedir}/src/test/resources</directory> 
         </testResource> 
        </testResources> 
    </build> 
    
    1

    저는 스프링 테스트 클래스와 junit으로 작업합니다.

    @RunWith(SpringJUnit4ClassRunner.class) 
    @ContextConfiguration(locations = "classpath:test-context.xml") 
    

    그리고 내 시험의 context.xml이었다에서 : SRC/테스트/자원/I와 함께 테스트를 주석

    <dependency> 
        <groupId>org.springframework</groupId> 
        <artifactId>spring-test</artifactId> 
        <version>3.2.1.RELEASE</version> 
    </dependency> 
    

    : 당신이 당신의 pom.xml에 올바른 종속성을 넣어 있는지 확인 test-context.xml

    그게 전부 야! 이 구성이 작동합니다!

    관련 문제