Spring1使用了DTD格式,spring2以后使用的是schema的格式;使用schema的格式,支持了不同类型的配置拥有了自己的命名空间,让配置文件有了更加好的扩展性。

不论什么事情,都是有利有弊,使用了schema格式,bean.xml的文件头的声明就会相对复杂非常多,每当我看到这些复杂的东东,我就觉的头的复杂了起来。

如《弟子规》所言,“功夫到 滞塞通”,这些东西,在实际工作中重复看,用心学,总能体会和了解的。

常见的spring配置说明

一个在简单项目中的完整bean.xml文件

<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/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
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd"> <bean id="role1" class="com.spring.Role"
p:name="范芳铭"
p:type="admin" /> <aop:config>
<aop:advisor pointcut=”execution(* *..facade.*(..))” advice-ref=”txAdvice” />
</aop:config>
</beans>
  • 1、 默认命名空间

http://www.springframework.org/schema/beans

它没有空间名称,用于Spring Bean的定义;

  • 2、 Xsi标准命名空间

xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”

这个命名空间为每一个文档中命名空间指定相应的schema样式,是标准组织定义的标准命名空间;

  • 3、 自己定义命名空间

xmlns:aop=”http://www.springframework.org/schema/aop”

aop是该命名空间的简称

http://www.springframework.org/schema/aop” 是该命名空间的全程,必须在xsi命名中间为它指定相应的schema文件。

这个命名空间分2步,一个是定义命名空间的名称(比方aop),然后指定命名空间样式文档的位置。

  • 4、 命名空间相应的schema文件
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/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
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd"

5、 默认命名空间配置

<bean id="role1" class="com.spring.Role" 
  • 6、 aop命名空间配置
<aop:config>
<aop:advisor pointcut=”execution(* *..facade.*(..))” advice-ref=”txAdvice” />

最新文章

  1. PM2的使用
  2. ZOJ 3861 - Valid Pattern Lock
  3. Java并发编程:并发容器之ConcurrentHashMap
  4. Java 控制反转和依赖注入模式【翻译】【整理】
  5. js中对style中的多个属性进行设值
  6. 以通配符(%)开始的like字符串,走索引
  7. 仿EXCEL插件,智表ZCELL产品V1.5 版本发布,IE8/9完全兼容
  8. 错误代码1045 Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password:YES)
  9. 记一次生产数据库&quot;意外&quot;重启的经历
  10. 面试官:你分析过SpringMVC的源码吗?
  11. redis底层设计(一)——内部数据结构
  12. 13.C# 定义类成员
  13. Oracle和sql server中复制表结构和表数据的sql语句
  14. Linux Home目录硬盘空间缩减
  15. easyui combobox下拉框复制后再禁用,点击不会出现下拉框
  16. Google Volley框架之https请求
  17. 《WAP》第一次作业:团队亮相
  18. EF:无法检查模型兼容性,因为数据库不包含模型元数据。
  19. linux学习笔记18--文件/chmod/chown/chgrp
  20. 转!!ftp学习

热门文章

  1. Kinect 骨骼映射---Let me dance for U!
  2. BZOJ 1588 HNOI2002 营业额统计 裸Treap
  3. 【翻译自mos文章】Clusterware间歇性的hang,命令报CRS-184而且Network Socket Files in /tmp/.oracle or /var/tmp/.oracle被删
  4. poj 2955 Brackets 括号匹配 区间dp
  5. 【Solr专题之九】SolrJ教程 分类: H4_SOLR/LUCENCE 2014-07-28 14:31 2351人阅读 评论(0) 收藏
  6. 三大主流ETL工具选型 分类: H2_ORACLE 2013-08-23 11:17 426人阅读 评论(0) 收藏
  7. jquery formcheck.js
  8. target属性值
  9. 编辑器vim简介
  10. 工具类与工具函数 —— NextPrime