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

  • 相关阅读:
    Android学习笔记八:String.Split("regex")相关
    Android转载六:Intent.ACTION
    Android学习笔记七:调用打电话、发短信等
    Android转载五:TextView换行问题
    常用正则表达式
    Android转载四:(布局)ImageView scaleType属性测试
    java并发容器类
    java并发编程-基础
    设计模式入门
    kafka模块概述
  • 原文地址:https://www.cnblogs.com/sknn/p/8057295.html
Copyright © 2011-2022 走看看