• Maven项目资源文件打包错误


    错误描述:

    org.springframework.beans.factory.BeanDefinitionStoreException: Could not resolve bean definition resource pattern [classpath:spring/spring-*.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/] cannot be resolved to URL because it does not exist

    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:229)

    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)

    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)

    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)

    ...

    Caused by: java.io.FileNotFoundException: class path resource [spring/] cannot be resolved to URL because it does not exist

    at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:187)

    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:463)

    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:292)

    at org.springframework.context.support.AbstractApplicationContext.getResources(AbstractApplicationContext.java:1296)

    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)... 61 more

    [WARNING] !RequestLog

    错误排查:首先检查xml中对相关配置文件的引入路径是否正确,本项目中有两处:

    对比路径,查看项目文件路径,发现文件都是存在的,说明并不是资源文件路径写错.

    路径没有错,而且文件也是确实存在的,检查mvn编译后的文件发现资源文件没有被编译,可以尝试重新编译;仍不能解决时,配置pom文件的build > resources标签,配置如下:

    <build>
      <finalName>ssm</finalName>
        <resources>
          <resource>
            <directory>src/main/resources</directory><!-- 资源文件所在文件夹 -->
            <includes>
              <include>*.properties</include><!-- 具体路径,按自己的项目配置 -->
              <include>**/*.properties</include>
              <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
          </resource>
        </resources>
        ...
    </build>

    原因是mvn在编译时,会将.properties和.xml文件过滤,不编译这些文件,在最后的war包中自然没有这些文件,引用时也就报错了.

  • 相关阅读:
    从一个集合中查找最大最小的N个元素——Python heapq 堆数据结构
    算法导论第二章小试牛刀
    python网络编程初级
    python基础的几个小练习题
    LeetCode:114_Flatten Binary Tree to Linked List | 将一棵二叉树变成链表的形式 | Medium
    LeetCode:111_Minimum Depth of Binary Tree | 二叉树的最小深度 | Easy
    LeetCode:110_Balanced Binary Tree | 平衡二叉树 | Easy
    LeetCode: 106_Construct Binary Tree from Inorder and Postorder Traversal | 根据中序和后序遍历构建二叉树 | Medium
    mysql中json_object函数的使用?
    mysql中json_remove函数的使用?
  • 原文地址:https://www.cnblogs.com/sknn/p/8057295.html
Copyright © 2020-2023  润新知