好记性不如烂笔头88-spring3学习(9)-schema的配置的解读和说明
2015-03-19 17:24
423 查看
Spring1使用了DTD格式,spring2以后使用的是schema的格式;使用schema的格式,支持了不同类型的配置拥有了自己的命名空间,让配置文件有了更加好的扩展性。
任何事情,都是有利有弊,使用了schema格式,bean.xml的文件头的声明就会相对复杂很多,每当我看到这些复杂的东东,我就觉的头的复杂了起来。
如《弟子规》所言,“功夫到 滞塞通”,这些东西,在实际工作中反复看,用心学,总能体会和了解的。
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文件
任何事情,都是有利有弊,使用了schema格式,bean.xml的文件头的声明就会相对复杂很多,每当我看到这些复杂的东东,我就觉的头的复杂了起来。
如《弟子规》所言,“功夫到 滞塞通”,这些东西,在实际工作中反复看,用心学,总能体会和了解的。
常见的spring配置说明
一个在简单项目中的完整bean.xml文件[code]<?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文件
[code]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"[/code]
5、 默认命名空间配置[code]<bean id="role1" class="com.spring.Role"
6、 aop命名空间配置[code]<aop:config> <aop:advisor pointcut=”execution(* *..facade.*(..))” advice-ref=”txAdvice” />
相关文章推荐
- 好记性不如烂笔头88-spring3学习(9)-schema的配置的解读和说明
- 好记性不如烂笔头89-spring3学习(10)-spring3常用schema(持续整理)
- 好记性不如烂笔头83-spring3学习(4)-spring的BeanFactory(IoC容器)
- 好记性不如烂笔头93-spring3学习(14)-spring事务传播机制的7剑客
- 好记性不如烂笔头85-spring3学习(6)-BeanFactory 中bean的生命周期
- 好记性不如烂笔头---hadoop配置调优
- 好记性不如烂笔头85-spring3学习(6)-BeanFactory 于bean生命周期
- 好记性不如烂笔头96-spring3学习(17)-利用debug观察事务传播
- 好记性不如烂笔头61-XML文档结构和属性说明
- 好记性不如烂笔头90-spring3学习(11)-小技巧汇总
- 好记性不如烂笔头98-spring3学习(19)-实施spring AOP事务的方法的漏网之鱼
- 好记性不如烂笔头97-spring3学习(18)-多线程模式下的spring事务
- 好记性不如烂笔头95-spring3学习(16)-spring配置log4j
- 好记性不如烂笔头86-spring3学习(7)-ApplicationContext中bean的生命周期
- 好记性不如烂笔头82-spring3学习(3)-spring的Resource使用和传统方法的对比
- 好记性不如烂笔头-.bash_profile配置hadoop,hive,hbase环境变量
- 好记性不如烂笔头86-spring3学习(7)-ApplicationContext中bean的生命周期
- 好记性不如烂笔头之 ——CP命令
- 好记性不如烂笔头
- 好记性不如烂笔头