Spring(3.2.3) - Beans(4): p-namespace & c-namespace
p 命名空间
p 命名空间允许你使用 bean 元素的属性而不是 <property/>子元素来描述 Bean 实例的属性值。从 Spring2.0 开始,Spring 支持基于 XML Schema 的方式来简化配置文件。beans 元素的结构定义在一个 XML Schema 文档中。但是,p 命名空间没有定义在 XSD 文件中,而是直接存在与 Spring 内核中。使用 p 命名空间时,只需要在配置文件根元素 beans 引入 xmlns:p="http://www.springframework.org/schema/p"。
p 命名空间配置的示例:
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="magicWand" class="com.huey.dream.bean.Weapon"
p:type="Magic Wand"
p:weightKg="9.5" /> <bean id="magician" class="com.huey.dream.bean.GameCharacter"
p:type="Magician"
p:level="10"
p:weapon-ref="magicWand" /> </beans>
上述的配置与如下的配置等价:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="magicWand" class="com.huey.dream.bean.Weapon">
<property name="type" value="Magic Wand" />
<property name="weightKg" value="9.5" />
</bean> <bean id="magician" class="com.huey.dream.bean.GameCharacter">
<property name="type" value="Magician" />
<property name="level" value="10" />
<property name="weapon" ref="magicWand" />
</bean> </beans>
c 命名空间
c 命名空间 与 p 命名空间用法类似,不同是 p 命名空间作用于属性注入,而 c 命名空间作用于构造注入。
p 命名空间配置的示例:
<?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:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="magicWand" class="com.huey.dream.bean.Weapon"
c:type="Magic Wand"
c:weightKg="9.5" /> <bean id="magician" class="com.huey.dream.bean.GameCharacter"
c:type="Magician"
c:level="10"
c:weapon-ref="magicWand" /> </beans>
上述的配置与如下的配置等价:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="magicWand" class="com.huey.dream.bean.Weapon">
<constructor-arg name="type" value="Magic Wand" />
<constructor-arg name="weightKg" value="9.5" />
</bean> <bean id="magician" class="com.huey.dream.bean.GameCharacter">
<constructor-arg name="type" value="Magician" />
<constructor-arg name="level" value="10" />
<constructor-arg name="weapon" ref="magicWand" />
</bean> </beans>
Spring(3.2.3) - Beans(4): p-namespace & c-namespace的更多相关文章
- Spring Security(十九):6. Security Namespace Configuration
6.1 Introduction Namespace configuration has been available since version 2.0 of the Spring Framewor ...
- Spring Framework------>version4.3.5.RELAESE----->Reference Documentation学习心得----->关于spring framework中的beans
Spring framework中的beans 1.概述 bean其实就是各个类实例化后的对象,即objects spring framework的IOC容器所管理的基本单元就是bean spring ...
- spring第一课,beans配置(中)——自动装配
•Spring IOC 容器可以自动装配 Bean. 需要做的仅仅是在 <bean> 的 autowire 属性里指定自动装配的模式 •byType(根据类型自动装配): 若 IOC 容器 ...
- Spring(3.2.3) - Beans(1): Spring 容器
BeanFactory & ApplicationContext org.springframework.beans.factory.BeanFactory 是最基本的 Spring 容器接口 ...
- Spring(3.2.3) - Beans(7): 延迟实例化
默认情况下,Spring IoC 容器启动后,在初始化过程中,会以单例模式创建并配置所有使用 singleton 定义的 Bean 的实例.通常情况下,提前实例化 Bean 是可取的,因为这样在配置中 ...
- Spring(3.2.3) - Beans(8): 基于 Annotation 的配置
除了基于 XML 的配置外,Spring 也支持基于 Annotation 的配置.Spring 提供以下介个 Annotation 来标注 Spring Bean: @Component:标注一个普 ...
- Spring(3.2.3) - Beans(10): 生命周期
Spring 容器可以管理 singleton 作用域 Bean 的生命周期,容器能够跟踪 Bean 实例的创建.销毁.管理 Bean 生命周期行为主要有两个时机: 注入 Bean 的依赖关系之后 即 ...
- spring applicationContext.xml中<beans>中属性概述
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...
- Spring Boot Unregistering JMX-exposed beans on shutdown
创建springboot项目运行的时候报这个错误Unregistering JMX-exposed beans on shutdown,搜索发现第一条是: Spring boot 嵌入的tomcat不 ...
随机推荐
- Unity3D之ScriptableObject学习笔记
不同与C#提供的Serializable序列化功能,ScriptableObject是Unity3D提供的一个数据存储类,我们接下来学习一下这个类的功能. 官方文档 http://docs.unity ...
- ASP.NET 尖括号 百分号 井号 等号 的用法
1.<%=%> 尖括号 百分号 等号 里面放的变量或方法,如: <div> <h1>Hello World</h1> <p><%= ...
- Android如何判断一个应用在运行
在一个应用中,或一个Service .Receiver中有时候需要判断一个应用是否正在运行,以便进行一些相关的处理,这个时候我们需要得到一个ActivityManager,这个Manager顾名思意就 ...
- PI-利用SoapUI 测试web service的方法介绍
在运用webservice调用数据的过程中,非常关键的一个步骤就是获取到webservice的地址,并测试webservice的连通情 况,webservice的连通测试主要是两个方面:1,查看web ...
- delphi 11 编辑模式 浏览模式
编辑模式 浏览模式 设置焦点 //在使用前需要Webbrowser已经浏览过一个网页 否则错误 uses MSHTML; ///获取Webbrowser编辑模式里面的内容procedure EditM ...
- Delphi 7连接MySql 5.5.15
原文:http://blog.csdn.net/akof1314/article/details/6822902/ 网上有很多关于Delphi连接MySql数据库的文章,在这里,我只记录下自己测试过的 ...
- android.content.res.Resources$NotFoundException:String resource ID #ffffffff
无语,搞了半天,只能去插这个错误代号,结果就找到了这个结果. scoreTextView.setText(score+""); 这个一定要自己手动转换..不科学啊..关键是在ecl ...
- Android 实现书籍翻页效果----完结篇
By 何明桂(http://blog.csdn.net/hmg25) 转载请注明出处 之前由于种种琐事,暂停了这个翻页效果的实现,终于在这周末完成了大部分功能,但是这里只是给出了一个基本的雏形,没有添 ...
- JavaScript提高:003:easy UI实现tab页面自适应问题
前面说到使用easyUI在asp.net中实现了tab控件效果.http://blog.csdn.net/yysyangyangyangshan/article/details/38307477只是有 ...
- shared_ptr的简单实现
前面讲到auto_ptr有个很大的缺陷就是所有权的转移,就是一个对象的内存块只能被一个智能指针对象所拥有.但我们有些时候希望共用那个内存块.于是C++ 11标准中有了shared_ptr这样的智能指针 ...