MAVEN项目,在IDEA中运行正常,但是把它打成jar包后再运行就会出现异常:
 
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: URL [jar:file:/home/jiashubing/mysoft/jartest3/cli3.jar!/META-INF/spring/spring-shell-plugin.xml]
 
这个错误并不少见,但是网上搜到的多为在项目运行的时候报这个错误。也有jar包中报这个错误的帖子,但是都说配置文件的版本不一致导致的。这些我都试过了,都无法解决。
 
尝试了很多次以后,终于发现,虽然我在项目中是有spring-shell-plugin.xml这个配置文件的,但是打成jar包以后,jar包中并没有包含这个配置文件
 
原来,在IDEA中,MAVEN项目是会自动扫描 src/main/resources 路径下的资源配置文件的,所以无需额外配置。
自动扫描的原因是:resource 下的文件编译之后存放的位置,直接位于classes下面,这个路径其实就是classPath的路径,所以,在resources 根目录下的配置文件其实就是 classPath的路径
 
 
但是打成Jar包以后,它是不会自动扫描 src/main/resources 路径下的配置文件了,所以应当在这里手动配置,让它能扫描到xml配置文件。
只需要在pom.xml中添加以下代码:
<resources>
   <resource>
      <directory>src/main/resources</directory>
      <includes>
         <include>**/*.xml</include>
      </includes>
   </resource>
</resources>
 
原创文章,转载请注明出处!

补充一下
MAVEN项目的标准目录结构:
 
src
  -main
      –bin 脚本库
      –java java源代码文件
      –resources 资源库,会自动复制到classes目录里
      –filters 资源过滤文件
      –assembly 组件的描述配置(如何打包)
      –config 配置文件
      –webapp web应用的目录。WEB-INF、css、js等
  -test
      –java 单元测试java源代码文件
      –resources 测试需要用的资源库
      –filters 测试资源过滤库
  -site Site(一些文档)
target
LICENSE.txt Project’s license
README.txt Project’s readme
 
红色字体的四个目录是常用的

打成Jar包后运行报错 Unable to locate Spring NamespaceHandler for XML schema namespace的更多相关文章

  1. 单点登录(十一)-----遇到问题-----cas启用mongodb验证方式报错--Unable to locate Spring NamespaceHandler for XML schema na

    cas启用mongodb验证方式报错--Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.sp ...

  2. 运行maven打出来的jar包报错:Unable to locate Spring NamespaceHandler for XML schema namespace

    问题背景:新建了一个maven项目,打了一个可运行jar包,依赖了spring几个jar包,一跑就报错了 E:\workspace\point-circle\target>java -jar p ...

  3. transaction 用tx事务 测试时 报错:Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/mvc]

    Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/sc ...

  4. jar项目 BeanDefinitionParsingException: Configuration problem:Unable to locate Spring NamespaceHandler for XML schema namespace

    最近由于项目需要,需要jar项目来处理. 我在项目中整合了Spring,在编辑器中启动没有问题,但是使用ant打包为一个完整jar文件,部署后启动报错如下 org.springframework.be ...

  5. mvn打包spring工程成jar时报Unable to locate Spring NamespaceHandler for XML schema namespace错误解决办法

    有一个小工程,使用了spring,在使用maven的assembly打包成独立可执行的jar包后,在执行时报如下错误:Configuration problem: Unable to locate S ...

  6. 整合mybatis时报错:Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/tx]

    org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Una ...

  7. Spring 3.0: Unable to locate Spring NamespaceHandler for XML schema namespace

    被这个问题折磨着很久:参考: http://have23.iteye.com/blog/1340777 (cfx 与 spring 整合的时候出现的问题: org.springframework.be ...

  8. [java] bug经验 Unable to locate Spring NamespaceHandler for XML schema namespace解决办法

    报错关键字: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration probl ...

  9. spring 与 CXF 整合 webservice 出现error “Unable to locate Spring NamespaceHandler for XML schema namespace” 总结

    我试了多个版本的spring 发现 出现error : Unable to locate Spring NamespaceHandler for XML schema namespace 并非都是sp ...

随机推荐

  1. Java上传和下载

    1.文件的上传 [1] 简介 > 将一个客户端的本地的文件发送到服务器中保存. > 上传文件是通过流的形式将文件发送给服务器. [2] 表单的设置 > 向服务器上传一个文件时,表单要 ...

  2. H5canvas画类似心电图

    HTML5 的 canvas 元素使用 JavaScript 在网页上绘制图像,我们可以使用canvas来绘制类似心电图的东西. 效果图如下: <!DOCTYPE html> <ht ...

  3. 计算pi的精度+进度条显示

    步骤1:安装tqdm 首先,要打开cmd,输入指令,不断找到python文件的路径,知道找到Scripts,然后分别打入pip install pygame和pip install tqdm  如下图 ...

  4. Python_day7

    sys模块 import sys def _add(a, b): return a + b def _sub(a, b): return a - b def _mul(a, b): return a ...

  5. 学以致用二十九-----python3连接mysql

    在前面安装好mysql后,在一个项目中需要连接mysql,python是3.6版本 python3连接mysql需要安装pymysql模块 可以通过pip安装 查看pip 版本 pip --versi ...

  6. 【慕课网实战】三、以慕课网日志分析为例 进入大数据 Spark SQL 的世界

    前置要求: 1)Building Spark using Maven requires Maven 3.3.9 or newer and Java 7+ 2)export MAVEN_OPTS=&qu ...

  7. ubuntu安装spyder和jupyter notebook

    ubuntu安装spyder和jupyter notebook 安装spyder 安装spyder sudo apt install spyder sudo apt install spyder3 安 ...

  8. kali 日志

    MAC协议安全攻防 kali 攻击 输入 macof -i eth0 -i 选择网卡 防御 使用交换机的安全特性 Port Security DCRS 需要开启 mac地址表学习使用cpu控制 mac ...

  9. easyui时的时间格式yyyy-MM-dd与yyyy-MM-ddd HH:mm:ss

    easyui日期的转换,日期汉化导入:<script type="text/javascript" src="../easyui/locale/easyui-lan ...

  10. Codeforces Round #421 (Div. 2)

    A: 题意:给你一本书共c页,第一天看v0页,第二天看v0+a,第二天看v0+2a以此类推,每天最多看v1页,但是后一天要重复看前一天的后l页. 代码: #include<stdio.h> ...