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” />

好记性不如烂笔头88-spring3学习(9)-schema的配置的解读和说明的更多相关文章

  1. 好记性不如烂笔头-linux学习笔记1

    好记性不如烂笔头-linux学习笔记1 linux的文件系统有ext2,ext3,ext4,目前主流是ext4 linux主要用于服务器级别的操作系统,安装时需要至少2个分区 一个是交换分区,swap ...

  2. 好记性不如烂笔头-Mysql查找如何判断字段是否包含某个字符串

    好记性不如烂笔头-Mysql查找如何判断字段是否包含某个字符串 利用mysql 字符串函数 find_in_set(); SELECT * FROM users WHERE find_in_set(' ...

  3. [nodejs]修改全局包位置,修复npm安装全局模块命令失效。好记性不如烂笔头

    修复npm -g 全局安装命令失效,好的吧不得不承认,好记性不如烂笔头,我居然会忘记方法哈哈哈 Linux安装nodejs sudo apt install node sudo apt install ...

  4. Common lang一些边界方法总结(好记性不如烂笔头,需要慢慢积累).一定要利用好现有的轮子,例如Apache common与Google Guava

    好记性真是不如烂笔头啊!!!! 如下代码: List<String> list = new ArrayList<String>(); list.add("1" ...

  5. 好记性不如烂笔头85-spring3学习(6)-BeanFactory 于bean生命周期

    假设BeanFactory为了产生.管理Bean, 一个Bean从成立到毁灭.它会经过几个阶段运行. 据我所知,一般bean包括在生命周期:设定,初始化,使用阶段,四个核心阶段销毁. 1.@Bean的 ...

  6. 好记性不如烂笔头-linux学习笔记2kickstart自动化安装和cacti

    kickstart自动化安装的逻辑梳理 主要是安装tftp nfs dhcp 然后配置kickstart 原来就是先安装tftp 可实现不同机器的文件下载 然后在安装nfs 就是主服务器的文件系统 然 ...

  7. 好记性不如烂笔头--linux学习笔记9练手写个shell脚本

    #!/bin/bash #auto make install httpd #by authors baker95935 #httpd define path variable H_FILES=http ...

  8. 好记性不如烂笔头--linux学习笔记8关于nginx的动静分离

    动静分离逻辑梳理 就是给nginx配置访问规则,不同后缀的文件访问不同的目录 worker_processes 1; events { worker_connections 1024; } http ...

  9. 好记性不如烂笔头-linux学习笔记6keepalived实现主备操作

    Keepalived的作用是检测服务器的状态,如果有一台web服务器宕机,或工作出现故障,Keepalived将检测到,并将有故障的服务器从系统中剔除,同时使用其他服务器代替该服务器的工作,当服务器工 ...

随机推荐

  1. Spring boot(二) springboot + jsp

    官方不推荐JSP在Spring Boot中使用! 一.添加依赖 在pim.xml 里面添加以下 jsp依赖 <dependency> <groupId>org.springfr ...

  2. 自定义控件三部曲之动画篇(一)——alpha、scale、translate、rotate、set的xml属性及用法

    前言:这几天做客户回访,感触很大,用户只要是留反馈信息,总是一种恨铁不成钢的心态,想用你的app,却是因为你的技术问题,让他们不得不放弃,而你一个回访电话却让他们尽释前嫌,当最后把手机号留给他们以便随 ...

  3. 编译Valgrind arm交叉编译

    1. 下载源码: http://valgrind.org/downloads/valgrind-3.9.0.tar.bz2   2. 加压缩: mkdir sw cd sw tar zxf valgr ...

  4. 苹果浏览器Safari对html标签submit按钮的默认渲染

    -webkit-appearance: none; 上面的设置就告诉Safari不要使用默认渲染,使用我们写好的 有这么一个webkit的私有属性: -webkit-appearance:none;  ...

  5. oracle listener.ora的host不能使localhost,而应该是该机器名,否则不能用ip地址进行连接

    # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/lis ...

  6. todo bitnami

    https://bitnami.com/stack/dokuwiki https://bitnami.com/stack/jenkins/installer

  7. 最新国内外可用SVN托管仓库有哪些

    最新国内外可用SVN托管仓库哪些 一.总结 一句话总结:用SVNBucket和SourceForge 二.最新国内外可用SVN托管仓库推荐 这几年很多SVN托管平台都基本不维护或者直接关闭了,我翻遍了 ...

  8. C/C++ 变量的初始化

    局部变量,初始化为垃圾值,局部静态变量初始化为 0: 1. 二维数组 // 作为局部变量 int arr[4]; // 全是垃圾值 int arr[4] = {1}; // 第一个元素为 1,其他默认 ...

  9. SpringMVC ModelAndView跳转失效

    今天隔壁的兄弟遇到一个奇怪的问题,他写好了一个表单用post提交到了addNew.do 里面,然后利用 return new ModelAndView("forward:success.js ...

  10. [Angular] Some performance tips

    The talk from here. 1. The lifecycle in Angular component: constructor vs ngOnInit: Constructor: onl ...