问题描述

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

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

在编译之后,报错:
Spring编译后没有xml配置文件解决方法

原因:

在编译后的文件目录中找不到xml配置文件:
Spring编译后没有xml配置文件解决方法

解决方法:

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

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

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

相关文章:

  • 2021-07-11
  • 2022-12-23
  • 2021-10-23
  • 2021-05-29
  • 2021-11-08
  • 2021-04-05
  • 2021-11-15
  • 2021-08-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2021-06-12
  • 2021-07-12
  • 2021-11-19
  • 2021-10-16
相关资源
相似解决方案