ClassPathResource 관련 문의입니다.

3,704 views
Skip to first unread message

mufasa

unread,
Jul 24, 2009, 12:34:14 AM7/24/09
to PRO SPRING 25_KOR
안녕하세요. ProSpring 2.5를 구입해서 읽고 있습니다.
2장의 예제를 실행해보려 하는데, 예외가 계속 발생하고 있습니다.

소스
==================================================
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
BeanDefinitionReader reader = new PropertiesBeanDefinitionReader
(bf);
reader.loadBeanDefinitions(new ClassPathResource("/META-INF/spring/
helloworld2-context.properties"));

MessageService service = (MessageService) bf.getBean("service");
service.execute();
====================================================
helloworld2-context.properties 파일 위치
D:\workspace\SpringTest\WebContent\META-INF\spring
====================================================
예외
Exception in thread "main"
org.springframework.beans.factory.BeanDefinitionStoreException: Could
not parse properties from class path resource [META-INF/spring/
helloworld-context.properties]; nested exception is
java.io.FileNotFoundException: class path resource [META-INF/spring/
helloworld-context.properties] cannot be opened because it does not
exist
at
org.springframework.beans.factory.support.PropertiesBeanDefinitionReader.loadBeanDefinitions
(PropertiesBeanDefinitionReader.java:270)
at
org.springframework.beans.factory.support.PropertiesBeanDefinitionReader.loadBeanDefinitions
(PropertiesBeanDefinitionReader.java:215)
at com.apress.prospring2.ch02.spring.FirstSpringHelloWorld.main
(FirstSpringHelloWorld.java:18)
Caused by: java.io.FileNotFoundException: class path resource [META-
INF/spring/helloworld-context.properties] cannot be opened because it
does not exist
at org.springframework.core.io.ClassPathResource.getInputStream
(ClassPathResource.java:143)
at
org.springframework.beans.factory.support.PropertiesBeanDefinitionReader.loadBeanDefinitions
(PropertiesBeanDefinitionReader.java:255)
... 2 more
===================================================

properties 파일을 찾지 못하고 있는데 경로도 바꾸어 보고 파일명을 바꾸어 보아도 마찬가지입니다.
어떻게 하면 해결할 수 있을까요?

감사합니다.

기선

unread,
Jul 24, 2009, 3:16:53 AM7/24/09
to PRO SPRING 25_KOR
소스 코드를 보면

reader.loadBeanDefinitions(
new ClassPathResource("/META-INF/spring/
helloworld2-context.properties"));


프로퍼티즈 파일이 spring/helloworld2 인데..

에러 메시지를 보면

org.springframework.beans.


factory.BeanDefinitionStoreException: Could
not parse properties from class path resource [META-INF/spring/
helloworld-context.properties]; nested exception is

프로퍼티 파일 이름에 2가 빠져있네요.


프로퍼티 파일 이름을 잘 맞춰주세요. 프로퍼티 파일을 못찾아서 발생한 에러 입니다.

wikibooks

unread,
Jul 24, 2009, 3:20:11 AM7/24/09
to PRO SPRING 25_KOR
역자이신 백기선님이 보내주신 답글입니다.

*************************

소스 코드를 보면

reader.loadBeanDefinitions(
new ClassPathResource("/META-INF/spring/
helloworld2-context.properties"));


프로퍼티즈 파일이 spring/helloworld2 인데..

에러 메시지를 보면

org.springframework.beans.


factory.BeanDefinitionStoreException: Could
not parse properties from class path resource [META-INF/spring/
helloworld-context.properties]; nested exception is

프로퍼티 파일 이름에 2가 빠져있네요.


프로퍼티 파일 이름을 잘 맞춰주세요. 프로퍼티 파일을 못찾아서 발생한 에러 입니다.

On 7월24일, 오후1시34분, mufasa <mufas...@gmail.com> wrote:

mufasa

unread,
Jul 24, 2009, 3:48:22 AM7/24/09
to PRO SPRING 25_KOR
먼저 바쁘실텐데 답변 주셔서 감사합니다.

말씀대로 오류가 있었기에, 수정했습니다.
파일명과 경로를 다시 한번 확인했었음에도 불구하고. 여전히 같은 오류가 납니다.
============================================================
[소스]
reader.loadBeanDefinitions(new ClassPathResource("D:/
LinkyPop_Workspace/SpringTest/WebContent/META-INF/spring/helloworld-
context.properties"));

[오류]
Caused by: java.io.FileNotFoundException: class path resource [D:/
LinkyPop_Workspace/SpringTest/WebContent/META-INF/spring/helloworld-


context.properties] cannot be opened because it does not exist

============================================================
그래서, 따로 File을 읽는 코드(FileInputStream 사용)를 추가해서 프로퍼티 파일을 읽도록 했는데 이렇게 하니 위
의 파일을 문제 없이 읽습니다.
혹시 ClassPathResource 클래스의 문제인가 싶어서,
reader.loadBeanDefinitions("D:\\LinkyPop_Workspace\\SpringTest\
\helloworld-context.properties"); 이렇게 바꾸어서 테스트를 해봐도 동일한 오류가 납니다.

제가 사용하는 스프링의 버전은 2.5.1 입니다. 혹시 이 버전에 버그가 있나요?

관심가져주시고, 답변 주셔서 다시한번 감사합니다.
혹시 저와 같은 오류가 나시는분은 안계신가요?

백기선

unread,
Jul 24, 2009, 3:57:05 AM7/24/09
to prospr...@googlegroups.com
ClassPathResource는 클래스패스 기준으로 리소스를 찾습니다.
D:/... 이런식으로 파일을 찾으실 거라면
FileSystemResource를 사용하시기 바랍니다.

프로퍼티즈 파일의 위치를 자바 파일과 동일한 클래스패스에 넣고

new ClassPathResource("xxxx.propertes") 라고 해보시죠.

프로퍼티즈 파일이 만약 whiteship 패키지에 있다면

new ClassPathResource("/whiteship/xxxx.propertes")

이렇게 사용하시면 됩니다.

여전히.. 스프링은 리소스 위치를 못찾고 있습니다.
만약에 스프링에 저런 버그가 있었다면... 스프링은 배포하질 않았을 겁니다.
설정 파일을 못찾는.. 치명적인 결함을 가지고 배포하진 않았겠죠.

2009년 7월 24일오후 4:48, mufasa <mufa...@gmail.com>님의 말:



--
좋은 하루 되세요~

mufasa

unread,
Jul 24, 2009, 4:30:07 AM7/24/09
to PRO SPRING 25_KOR
답변 정말 감사합니다.
FileSystemResource 사용해서 해결했습니다.

고맙습니다.
좋은 주말 되시길 바랍니다.

백기선

unread,
Jul 24, 2009, 4:36:49 AM7/24/09
to prospr...@googlegroups.com
넵 좋은 주말 되세요~

2009년 7월 24일오후 5:30, mufasa <mufa...@gmail.com>님의 말:



--
좋은 하루 되세요~
Reply all
Reply to author
Forward
0 new messages