소스
==================================================
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 파일을 찾지 못하고 있는데 경로도 바꾸어 보고 파일명을 바꾸어 보아도 마찬가지입니다.
어떻게 하면 해결할 수 있을까요?
감사합니다.
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가 빠져있네요.
프로퍼티 파일 이름을 잘 맞춰주세요. 프로퍼티 파일을 못찾아서 발생한 에러 입니다.
*************************
소스 코드를 보면
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:
말씀대로 오류가 있었기에, 수정했습니다.
파일명과 경로를 다시 한번 확인했었음에도 불구하고. 여전히 같은 오류가 납니다.
============================================================
[소스]
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 입니다. 혹시 이 버전에 버그가 있나요?
관심가져주시고, 답변 주셔서 다시한번 감사합니다.
혹시 저와 같은 오류가 나시는분은 안계신가요?
고맙습니다.
좋은 주말 되시길 바랍니다.