2011-03-03 3 views
0

웹 응용 프로그램을 시작할 때 Groovy 스크립트를 실행하려고합니다. 나는 Spring Recipes라는 책의 예를 따르려고합니다. com.apress.springrecipes.interestGroovy Spring Bean 클래스 경로

콩 패키지는 패키지 com.wer.comsrc/test/resources에, 그리고 콩이 곳이다 -

나는 다음과 같은 패키지에 SimpleInterestCalculator 있습니다. 점에서

내 항목은

<lang:groovy id="interestCalculator" script-source="classpath:com/apress/springrecipes/interest/SimpleInterestCalculator.groovy"> 
    <lang:property name="rateCalculator" value="rateCalculator" /> 
</lang:groovy> 

나는 다음과 같은 오류를 얻고있다.

Caused by: org.springframework.beans.factory.BeanCreationException: 
    Error creating bean with name 'simpleInterestCalculator': 
    Could not determine scripted object type for GroovyScriptFactory: 
    script source locator [classpath:src/com/apress/springrecipes/interest/SimpleInterestCalculator.groovy]; 
    nested exception is java.io.FileNotFoundException: 
    class path resource [src/com/apress/springrecipes/interest/SimpleInterestCalculator.groovy] cannot be opened because it does not exist 
+1

이미 Spring 애플리케이션 시작시 Groovy 스크립트를 실행하는 방법을 설명했다. 비슷한 새로운 질문을하기 전에 해당 대답을 수락하거나 의견을 말하십시오. –

답변

3

오류는 FileNotFoundException입니다. 이것은 스크립트 파일 자체를 찾지 못함을 의미합니다. 파일이 있으면 런타임시 classpath에 없을 수도 있습니다.

IDE에서 bin/out 디렉토리를 확인하여 .groovy 파일이 있는지 확인하십시오. 때로는 소스 디렉토리에 .groovy가 있으면 IDE가 '소스'코드라고 가정하고 바이트 코드로 컴파일합니다. 결과적으로 Groovy 스크립트 자체가 아닌 클래스 경로에서 .class 파일로 끝납니다. 이것은 설정 및 사용중인 IDE에 따라 다릅니다. 문제가있는 것 같으면이 옵션이 있거나 컴파일러에서 선택하지 않는 대체 확장을 사용할 수 있습니다.