복붙노트

[SPRING] Spring FileSystemXmlApplicationContext가 빈 구성 파일을 찾지 못하고 오류가 발생합니다.

SPRING

Spring FileSystemXmlApplicationContext가 빈 구성 파일을 찾지 못하고 오류가 발생합니다.

ApplicationContext 인터페이스의 구현으로 FileSystemXmlApplicationContext를 사용하는 다음 Spring "Hello World"예제를 수행하려고합니다.

이 구현은 앞의 예와 같이 XML Bean 구성의 전체 경로를 생성자 매개 변수로 가져와야합니다.

ApplicationContext context = new FileSystemXmlApplicationContext("C:/Users/ZARA/workspace/HelloSpring/src/Beans.xml");

Linux를 사용하고 Beans 구성 파일은 다음 경로에 있습니다. /home/andrea/Documents/ws/myapplicationcontextexample/src/main/java/Beans.xml, 그래서 내 코드에서 :

ApplicationContext context = new FileSystemXmlApplicationContext("/home/andrea/Documents/ws/myapplicationcontextexample/src/main/java/Beans.xml");

문제는 응용 프로그램을 실행할 때 STS \ Eclipse 콘솔에서 다음 오류 메시지가 나타납니다 (파일을 찾지 못하는 것 같습니다).

INFO: Loading XML bean definitions from file [/home/andrea/Documents/ws/myapplicationcontextexample/home/andrea/Documents/ws/myapplicationcontextexample/src/main/java/Beans.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [/home/andrea/Documents/ws/myapplicationcontextexample/home/andrea/Documents/ws/myapplicationcontextexample/src/main/java/Beans.xml]; nested exception is java.io.FileNotFoundException: home/andrea/Documents/ws/myapplicationcontextexample/src/main/java/Beans.xml (File o directory non esistente)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
    at org.andrea.myexample.myapplicationcontextexample.MainApp.main(MainApp.java:14)
Caused by: java.io.FileNotFoundException: home/andrea/Documents/ws/myapplicationcontextexample/src/main/java/Beans.xml (File o directory non esistente)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at org.springframework.core.io.FileSystemResource.getInputStream(FileSystemResource.java:113)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
    ... 13 more

왜? 어떻게 해결할 수 있습니까?

Txx

안드레아

해결법

  1. ==============================

    1.참조 : http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/context/support/FileSystemXmlApplicationContext.html

    참조 : http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/context/support/FileSystemXmlApplicationContext.html

  2. from https://stackoverflow.com/questions/14483160/spring-filesystemxmlapplicationcontext-dont-find-the-bean-configuration-file-an by cc-by-sa and MIT license