今天在Spring配置文件中配置如下事务属性时,提示<tx is not bound(不受约束的),估计是配置文件的xsd没配置好。

<!-- 2.配置事务属性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true"></tx:method>
<tx:method name="*"></tx:method>
</tx:attributes>
</tx:advice>

在xsi:schemaLocation=中增加:

http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

错误就消失了。

网上查阅了相关资料,现总结如下:

xml文档要有格式,为了Spring的配置文件增加的节点(比如<tx:advice)能符合要求、合法,必须通过引入校验该xml格式的文件,也就是xsd文件。Spring通过配置可以联网引入xsd文件,也可以在断网下使用本地xsd文件校验xml文件。

xsi:schemaLocation 属性提供一种方法来查找在 XML 实例文档中定义的命名空间的 XML 架构定义。它的值是用空白分隔的统一资源标识符 (URI) 对的列表,其中的每一对 URI 都依次包含一个命名空间以及该命名空间的 XML 架构定义(通常为 .xsd 文件)的位置。

xsi:schemaLocation 提供了xml的namespace到对应的xsd文件的映射,从下列配置可以看出xsi:schemaLocation 里面配置的字符串都是成对的,前面是namespace的URI,后面是xsd文件的URI

    xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

Spring在启动时默认要加载xsd文件来验证XML文件的,在浏览器中输入复制的xmlns:tx的链接,也就是http://www.springframework.org/schema/tx,可以看到如下页面:

以上都是可选的tx的xsd版本,而xsi:schemaLocation的http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 在用浏览器访问是该版本xsd对应内容的页面:

箭头指的就是对<tx:advice进行xml校验的部分,从上面代码看出,tx还可以添加<tx:annotation-driven,<tx:jta-transaction-manager 节点,这个与xml中的提示是一致的:

advice部分的具体代码如下:

 <xsd:element name="advice">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation source="java:org.springframework.transaction.interceptor.TransactionInterceptor">
<![CDATA[
Defines the transactional semantics of the AOP advice that is to be executed. That is, this advice element is where the transactional semantics of any number of methods are defined (where transactional semantics includes the propagation settings, the isolation level, the rollback rules, and suchlike).
]]>
</xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="org.springframework.transaction.interceptor.TransactionInterceptor"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="beans:identifiedType">
<xsd:sequence>
<xsd:element name="attributes" type="attributesType" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="transaction-manager" type="xsd:string" default="transactionManager">
<xsd:annotation>
<xsd:documentation source="java:org.springframework.transaction.PlatformTransactionManager">
<![CDATA[
The bean name of the PlatformTransactionManager that is to be used to drive transactions. This attribute is not required, and only needs to be specified explicitly if the bean name of the desired PlatformTransactionManager is not 'transactionManager'.
]]>
</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.transaction.PlatformTransactionManager"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>

如果此时无法上网,就无法从该网站获取到该xsd文件,就无法对xml文件进行校验了,容易发生应用启动不了的情况。为此我们可以加载本地的xsd文件,这样断网情况下也可以启动应用了。举例子来说,若tx的xsd文件没有配置,则要进行如下步骤进行配置

1、点开项目的lib,找到spring-tx-4.1.4.RELEASE.jar,右键属性-复制文件路径(复制jar之前的路径),在文件夹地址栏粘贴,回车打开;

2、将spring-tx-4.1.4.RELEASE.jar解压到某个文件夹,有如下文件:

3、在org\springframework\transaction\config路径下可以找到:

里面还有旧版本的xsd文件,这样可以避免配置文件用的还是旧版本的xsd文件,而Spring是新版本情况下,断网应用启动不了的情况。Spring这个确实想得挺周到的。

4、将tx的某个版本的xsd文件拷贝到工程的source folder下,然后xml的配置改成如下形式:

xsi:schemaLocation="http://www.springframework.org/schema/beans
classpath:beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/mvc
classpath:mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/context
classpath:context/spring-context-4.1.xsd
http://www.springframework.org/schema/aop
classpath:aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/tx
classpath:tx/spring-tx-4.1.xsd ">

这样就可以从本地获取xsd文件,就算断网也可以解析xml文件了。

附一份常见的spring配置文件的文件头:

------------------------------------3.0----------------------------

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> </beans>

当然你也可以根据使用的Spring的相应jar包版本更改对应的版本,比如上面的3.0可以改成4.1也行

http://www.springframework.org/schema/  该网站是Spring所有可能用到的结点属性的xsd列表,点击相应选项即可查到对应的xsd版本与xsd的URI:

Spring配置文件的xsd知识点的更多相关文章

  1. spring配置文件中xsd引用问题

    XML的一些概念 首先来看下xml的一些概念: xml的schema里有namespace,可以给它起个别名.比如常见的spring的namespace:   xmlns:mvc="http ...

  2. 转:spring配置文件中xsd引用问题

    来自:http://blog.csdn.net/dingqinghu/article/details/46758671

  3. spring 配置文件XSD地址

    这边部署不能访问外网,所以sping配置文件里的XSD地址要改一下象  http://www.springframework.org/schema/beans/spring-beans-2.0.xsd ...

  4. eclipse spring 配置文件xml校验时,xsd报错

      1.情景展示 eclipse中,spring配置文件报错信息如下: 配置文件头部引用信息为: <?xml version="1.0" encoding="UTF ...

  5. Spring配置文件头及xsd文件版本

    最初Spring配置文件的头部声明如下: Xml代码   <?xml version="1.0" encoding="UTF-8"?> <!D ...

  6. 你不知道的Spring配置文件

    Spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的"图纸".Java EE程序员必须学会并灵活应用这份"图纸&quo ...

  7. Spring配置文件详解

      转自: http://book.51cto.com/art/201004/193743.htm 此处详细的为我们讲解了spring2.5的实现原理,感觉非常有用 spring配置文件是用于指导Sp ...

  8. spring配置文件详解--真的蛮详细

    spring配置文件详解--真的蛮详细   转自: http://book.51cto.com/art/201004/193743.htm 此处详细的为我们讲解了spring2.5的实现原理,感觉非常 ...

  9. Spring 配置文件详解 (以2.5为例)

    转载自:http://blog.csdn.net/zzjjiandan/article/details/22922847          Spring配置文件是用于指导Spring工厂进行Bean生 ...

随机推荐

  1. ASP.NET Core API 版本控制

    几天前,我和我的朋友们使用 ASP.NET Core 开发了一个API ,使用的是GET方式,将一些数据返回到客户端 APP.我们在前端进行了分页,意味着我们将所有数据发送给客户端,然后进行一些dat ...

  2. python基础(7):字符编码

    今天我们进入字符编码的学习.字符编码是一个多理论少结论的知识点,我会总结很多的知识点.我们只需要通读当作了解即可,最后我会总结需要我们理解掌握的重点. 一.学习字符编码的计算机基础储备 1.计算机软件 ...

  3. RxSwift 实战操作【注册登录】

    前言 看了前面的文章,相信很多同学还不知道RxSwift该怎么使用,这篇文件将带领大家一起写一个 注册登录(ps:本例子采用MVVM)的例子进行实战.本篇文章是基于RxSwift3.0写的,采用的是C ...

  4. 初始jvm(一)---jvm内存区域与溢出

    jvm内存区域与溢出 为什么学习jvm 木板原理,最短的一块板决定一个水的深度,当一个系统垃圾收集成为瓶颈的时候,那么就需要你对jvm的了解掌握. 当一个系统出现内存溢出,内存泄露的时候,因为你懂jv ...

  5. java循环

    .增强for循环和iterator遍历的效果是一样的,也就说增强for循环的内部也就是调用iteratoer实现的(可以查看编译后的文件),但是增强for循环 有些缺点,例如不能在增强循环里动态的删除 ...

  6. npm的package.json字段含义中文文档

    简介 本文档有所有package.json中必要的配置.它必须是真正的json,而不是js对象. 本文档中描述的很多行为都受npm-config(7)的影响. 默认值 npm会根据包内容设置一些默认值 ...

  7. Hibernate的系统 学习

    Hibernate的系统 学习 一.Hibernate的介绍 1.什么是Hibernate? 首先,hibernate是数据持久层的一个轻量级框架.数据持久层的框架有很多比如:iBATIS,myBat ...

  8. 35. leetcode 501. Find Mode in Binary Search Tree

    501. Find Mode in Binary Search Tree Given a binary search tree (BST) with duplicates, find all the  ...

  9. Struts2漏洞解决

    如果你也正在使用Struts2作为web层框架做开发或者做公司的送检产品,然后被告知有各种各样的Struts2漏洞,那本篇博客值得你花时间来喽上一两眼. 前端时间抽空为公司做了新一代的送检产品,为了方 ...

  10. iOS底层学习-KVC使用实践以及实现原理

    简介 KVC(Key-value coding)键值编码,顾名思义.额,简单来说,是可以通过对象属性名称(Key)直接给属性值(value)编码(coding)"编码"可以理解为& ...