maven创建的quickstart 识别不到applicationContext.xml

1、错误

maven项目java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be resolve

 2、描述:

用 maven 创建的 quickstart 项目,配置 好了 Spring xml配置文件,启动报错 maven项目java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be resolve

ApplicationContext appCon = new ClassPathXmlApplicationContext("applicationContext.xml");

 3、分析:

maven-quickstart 项目的 classpath 默认是 src/main/java,当我们把 applicationContext.xml 放置到 src/main/java 文件下,运行确报错“资源找不到”,说明 maven 打包运行的时候,没有将 *.xml 文件包含进去,手动配置添加即可,配置如下:

<build>
    ...

    <!--加如下配置防止maven打包时xml文件或properties文件打包不进去-->
    <resources>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
      </resource>
    </resources>

    ...
</build>
原文地址:https://www.cnblogs.com/lkc9/p/12181605.html