Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pro Spring 3book类路径资源[app context annotation.xml]不存在,无法打开_Spring - Fatal编程技术网

Pro Spring 3book类路径资源[app context annotation.xml]不存在,无法打开

Pro Spring 3book类路径资源[app context annotation.xml]不存在,无法打开,spring,Spring,我正试图通过学习专业版Spring3来学习Spring3。我在第4章中,作者解释了IoC和DI。他使用GenericXmlApplicationContext指定配置文件。他做了以下工作: package com.apress.prospring3.ch4; import org.springframework.context.support.GenericXmlApplicationContext; public class UsingSetterInjection { publ

我正试图通过学习专业版Spring3来学习Spring3。我在第4章中,作者解释了IoC和DI。他使用GenericXmlApplicationContext指定配置文件。他做了以下工作:

package com.apress.prospring3.ch4;

import org.springframework.context.support.GenericXmlApplicationContext;

public class UsingSetterInjection {

    public static void main(String[] args) {

        GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
        //ctx.load("classpath:app-context-xml.xml");
        ctx.load("classpath:app-context-annotation.xml");
        ctx.refresh();      

        MessageRenderer messageRenderer = ctx.getBean("messageRenderer", MessageRenderer.class);
        messageRenderer.render();
    }
}
我的结构是

src/main/resources/app-context-annotation.xml


IOException解析来自类路径资源[app context annotation.XML]的XML文档;嵌套异常为java.io.FileNotFoundException:无法打开类路径资源[app context annotation.xml],因为它不存在

能否尝试使用以下行加载xml文件

ctx.load("classpath*:app-context-annotation.xml");
我在类路径后添加了一个*。我想这应该能解决你的问题。否则,您需要检查应用程序类路径中是否存在此文件


干杯。

给出完整的路径,它将像一个符咒一样工作

    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:META-INF/spring/app-context-annotation.xml");

您是否创建了名为“app context xml.xml”的Spring配置文件?如果是这样,请确保已将其添加到应用程序的类路径中。我的结构是src/main/resources/app-context-annotation.xml首先,学会接受答案!第二,我打赌你正在使用Maven。检查是否存在target/classes/app-context-annotation.xml。如果没有,那么您甚至还没有编译您的编解码器。您可以检查部署的应用程序的classes文件夹中的xml吗?如果它在classes文件夹中,那么肯定还有另一个问题。