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

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

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

常见的spring配置说明

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

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:tx="http://www.springframework.org/schema/tx"
  6. xmlns:p="http://www.springframework.org/schema/p"
  7. xmlns:aop="http://www.springframework.org/schema/aop"
  8. xmlns:task="http://www.springframework.org/schema/task"
  9. xsi:schemaLocation="
  10. http://www.springframework.org/schema/beans
  11. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  12. http://www.springframework.org/schema/context
  13. http://www.springframework.org/schema/context/spring-context-3.0.xsd
  14. http://www.springframework.org/schema/tx
  15. http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
  16. http://www.springframework.org/schema/aop
  17. http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
  18. http://www.springframework.org/schema/task
  19. http://www.springframework.org/schema/task/spring-task.xsd">
  20. <bean id="role1" class="com.spring.Role"
  21. p:name="范芳铭"
  22. p:type="admin" />
  23. <aop:config>
  24. <aop:advisor pointcut=”execution(* *..facade.*(..))” advice-ref=”txAdvice” />
  25. </aop:config>
  26. </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文件
  1. xsi:schemaLocation="
  2. http://www.springframework.org/schema/beans
  3. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  4. http://www.springframework.org/schema/context
  5. http://www.springframework.org/schema/context/spring-context-3.0.xsd
  6. http://www.springframework.org/schema/tx
  7. http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
  8. http://www.springframework.org/schema/aop
  9. http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
  10. http://www.springframework.org/schema/task
  11. http://www.springframework.org/schema/task/spring-task.xsd"

5、 默认命名空间配置

  1. <bean id="role1" class="com.spring.Role"
  • 6、 aop命名空间配置
  1. <aop:config>
  2. <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. 使用openoffice转换ms_office to pdf

    java源代码: package com.jeecms.common.office2pdf; import java.io.File; import java.io.FileInputStream; ...

  2. Access Violations 访问冲突(AVs)是Windows编程时发生的最麻烦的错误?

    Access Violations<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office&qu ...

  3. INotifyPropertyChanged接口的详细说明

    在windows phone开发8.1:数据绑定中,我们了解了数据绑定的基本知识.今后几篇文章会继续深入了解数据绑定.今天我们来看在数据绑定中十分重要的INotifyPropertyChanged接口 ...

  4. SpringCloud微服务框架搭建

    一.微服务架构 1.1什么是分布式 不同模块部署在不同服务器上 作用:分布式解决网站高并发带来问题 1.2什么是集群 多台服务器部署相同应用构成一个集群 作用:通过负载均衡设备共同对外提供服务 1.3 ...

  5. 【76.57%】【codeforces 721A】One-dimensional Japanese Crossword

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. php课程 4-17 数组键值操作函数有哪些

    php课程 4-17  数组键值操作函数有哪些 一.总结 一句话总结:多看学习视频 1.php中数组的键值操作函数有哪6个? • array_values();获取数组中的值• array_keys( ...

  7. Redis的增删改查、持久化你会了吗

    原文:Redis的增删改查.持久化你会了吗 Redis是用C语言实现的,一般来说C语言实现的程序"距离"操作系统更近,执行速度相对会更快. Redis使用了单线程架构,预防了多线程 ...

  8. Java程序猿的JavaScript学习笔记(5——prototype和Object内置方法)

    计划按例如以下顺序完毕这篇笔记: Java程序猿的JavaScript学习笔记(1--理念) Java程序猿的JavaScript学习笔记(2--属性复制和继承) Java程序猿的JavaScript ...

  9. [ES2016] Check if an array contains an item using Array.prototype.includes

    We often want to check if an array includes a specific item. It's been common to do this with the Ar ...

  10. epoll 和select

    epoll 水平触发和边缘触发的区别 EPOLLLT——水平触发EPOLLET——边缘触发 epoll有EPOLLLT和EPOLLET两种触发模式,LT是默认的模式,ET是“高速”模式.LT模式下,只 ...