zoukankan      html  css  js  c++  java
  • 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包中自然没有这些文件,引用时也就报错了.

  • 相关阅读:
    吴恩达深度学习与神经网络
    吴恩达机器学习的ppt以及作业编程练习题答案(别人总结的)
    关于机器学习的小科普
    质因数分解
    FFT
    Luogu P1262 间谍网络
    关于次短路
    Luogu P1955 [NOI2015]程序自动分析
    Luogu P1041传染病控制
    Bzoj 1731 POJ 3169 Luogu P4878 Layout
  • 原文地址:https://www.cnblogs.com/sknn/p/8057295.html
Copyright © 2011-2022 走看看