4

春のコンテキストに非常に奇妙な問題があります。

public static void main(String[] args) {


    File file = new File("/home/user/IdeaProjects/Refactor/src/spring-cfg.xml");
    System.out.println("Exist "+file.exists());
    System.out.println("Path "+file.getAbsoluteFile());

    ApplicationContext context = new ClassPathXmlApplicationContext(file.getAbsolutePath());

コンソールに表示:

Exist true
Path /home/user/IdeaProjects/Refactor/src/spring-cfg.xml

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [home/user/IdeaProjects/Refactor/src/spring-cfg.xml]; nested exception is java.io.FileNotFoundException: class path resource [home/user/IdeaProjects/Refactor/src/spring-cfg.xml] cannot be opened because it does not exist
4

4 に答える 4

0

このコードはうまくいくと思います

ApplicationContext context = 
    new FileSystemXmlApplicationContext("file:/home/user/IdeaProjects/Refactor/src/spring-cfg.xml");

ここで役立つ情報を見つけることができますhttp://static.springsource.org/spring/docs/2.5.6/reference/resources.html

于 2013-06-11T21:00:17.057 に答える