我随意写,你随意看。

林老头儿

但愿绝望和无奈远走高飞

Fork me on Gitee

Spring编译后没有xml配置文件解决方法

问题描述

在使用Maven来构建Spring项目的时候,使用下面代码来读取Spring配置文件。

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/com/lin/test1/spring_config.xml");

在编译之后,报错:
在这里插入图片描述

原因:

在编译后的文件目录中找不到xml配置文件:
在这里插入图片描述

解决方法:

在pom.xml文件中增加配置:

    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

这时候编译后存放class的文件夹下就会存在xml的配置文件。

posted @ 2019-10-23 14:41  林老头儿  阅读(954)  评论(1编辑  收藏  举报