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的配置文件。

猜你喜欢

转载自www.cnblogs.com/mrlin1996/p/11726196.html