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包中自然没有这些文件,引用时也就报错了.

  • 相关阅读:
    CC2540-BLE4.0 学历笔记1之串口体验
    cc2530的PWM实现
    用qt写的一个简单到不能在简单的上位机
    在Kubuntu14.04中安装小企鹅输入法
    初始化umi项目
    工具杂记(三) -- zookeeper
    工具杂记(二) -- Centos7
    工具杂记(一) -- vagrant
    (一)Docker导学
    JVM随笔(二)之搜索类
  • 原文地址:https://www.cnblogs.com/sknn/p/8057295.html
Copyright © 2011-2022 走看看