`
mcj8089
  • 浏览: 191155 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

使用spring做java的swing客户端报错:找不到元素 'beans' 的声明 或者 找不到元素 'tx' 的声明。

阅读更多

使用Java语言编写Swing客户端,其中用到事物TX,spring头配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
	http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">

 

结果在运行时报错:找不到元素 'beans' 的声明。

 

原因分析:xsd文件加载异常在spring的jar包中org.springframework.beans-3.1.0.M2.jar、org.springframework.transaction-3.1.0.M2.jar存在三个文件,spring.handlers,spring.schemas,spring.tooling,他们位于org.springframework.beans.factory.xml目录下;由于开发swing客户端,在导出最终的jar包时三个文件被多个jar包中的同名文件依次覆盖,导致配置缺失(只存在事物配置 或 只存在beans配置)。

 

解决方案:

 

新建三个文件,把beans配置和事物配置都写进去,分别如下:

 

spring.handlers

#beans支持
http\://www.springframework.org/schema/c=org.springframework.beans.factory.xml.SimpleConstructorNamespaceHandler
http\://www.springframework.org/schema/p=org.springframework.beans.factory.xml.SimplePropertyNamespaceHandler
http\://www.springframework.org/schema/util=org.springframework.beans.factory.xml.UtilNamespaceHandler

#事物支持
http\://www.springframework.org/schema/tx=org.springframework.transaction.config.TxNamespaceHandler

 

spring.schemas

#beans支持
http\://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http\://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.1.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd
http\://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd
http\://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd
http\://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd
http\://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd
http\://www.springframework.org/schema/util/spring-util-3.1.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd
http\://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd
#事物支持
http\://www.springframework.org/schema/tx/spring-tx-2.0.xsd=org/springframework/transaction/config/spring-tx-2.0.xsd
http\://www.springframework.org/schema/tx/spring-tx-2.5.xsd=org/springframework/transaction/config/spring-tx-2.5.xsd
http\://www.springframework.org/schema/tx/spring-tx-3.0.xsd=org/springframework/transaction/config/spring-tx-3.0.xsd
http\://www.springframework.org/schema/tx/spring-tx-3.1.xsd=org/springframework/transaction/config/spring-tx-3.1.xsd
http\://www.springframework.org/schema/tx/spring-tx.xsd=org/springframework/transaction/config/spring-tx-3.1.xsd

 

 

spring.tooling

# Tooling related information for the beans namespace
http\://www.springframework.org/schema/beans@name=beans Namespace
http\://www.springframework.org/schema/beans@prefix=beans
http\://www.springframework.org/schema/beans@icon=org/springframework/beans/factory/xml/spring-beans.gif

# Tooling related information for the util namespace
http\://www.springframework.org/schema/util@name=util Namespace
http\://www.springframework.org/schema/util@prefix=util
http\://www.springframework.org/schema/util@icon=org/springframework/beans/factory/xml/spring-util.gif

# Tooling related information for the tx namespace
http\://www.springframework.org/schema/tx@name=tx Namespace
http\://www.springframework.org/schema/tx@prefix=tx
http\://www.springframework.org/schema/tx@icon=org/springframework/transaction/config/spring-tx.gif

 

 用rar查看软件打开swing导出的最终的jar包,把上面三个文件推拽近最终jar包的META-INF目录下,覆盖里面存在的三个文件,问题即可以解决了。



 

 

 

  • 大小: 83.7 KB
0
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics