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 - IoC(4): p-namespace & c-namespace的更多相关文章

  1. Spring解决Attribute tx bound to namespace httpwww.w3.org2000xmlns was already specified

    Spring|解决Attribute "tx" bound to namespace "http://www.w3.org/2000/xmlns/" was a ...

  2. TinyFrame续篇:整合Spring IOC实现依赖注入

    上一篇主要讲解了如何搭建基于CodeFirst的ORM,并且在章节末我们获取了上下文对象的实例:BookContext.这节主要承接上一篇,来讲解如何整合Spring IOC容器实现控制反转,依赖注入 ...

  3. 对Spring IoC容器实现的结构分析

    本文的目标:从实现的角度来认识SpringIoC容器. 观察的角度:从外部接口,内部实现,组成部分,执行过程四个方面来认识SpringIoC容器. 本文的风格:首先列出SpringIoC的外部接口及内 ...

  4. Spring IOC之基于JAVA的配置

    基础内容:@Bean 和 @Configuration 在Spring中新的支持java配置的核心组件是 @Configuration注解的类和@Bean注解的方法. @Bean注解被用于表明一个方法 ...

  5. Spring IOC之依赖

    一个标准的企业级应用不只有一个对象组成.即使是最简单的引用也会有个相互作用的对象以使最终呈现 在用户面前的是个连贯一致的引用. 1依赖注入 依赖注入(DI)是一个对象定义他们依赖的过程,也就是说他们一 ...

  6. Spring IOC 容器源码分析

    声明!非原创,本文出处 Spring 最重要的概念是 IOC 和 AOP,本篇文章其实就是要带领大家来分析下 Spring 的 IOC 容器.既然大家平时都要用到 Spring,怎么可以不好好了解 S ...

  7. Spring IOC 源码分析

    Spring 最重要的概念是 IOC 和 AOP,本篇文章其实就是要带领大家来分析下 Spring 的 IOC 容器.既然大家平时都要用到 Spring,怎么可以不好好了解 Spring 呢?阅读本文 ...

  8. Spring IOC 容器源码分析(转)

    原文地址 Spring 最重要的概念是 IOC 和 AOP,本篇文章其实就是要带领大家来分析下 Spring 的 IOC 容器.既然大家平时都要用到 Spring,怎么可以不好好了解 Spring 呢 ...

  9. Spring源码剖析2:Spring IOC容器的加载过程

    spring ioc 容器的加载流程 1.目标:熟练使用spring,并分析其源码,了解其中的思想.这篇主要介绍spring ioc 容器的加载 2.前提条件:会使用debug 3.源码分析方法:In ...

  10. Spring4- 01 - Spring框架简介及官方压缩包目录介绍- Spring IoC 的概念 - Spring hello world环境搭建

    一. Spring 框架简介及官方压缩包目录介绍 主要发明者:Rod Johnson 轮子理论推崇者: 2.1 轮子理论:不用重复发明轮子. 2.2 IT 行业:直接使用写好的代码. Spring 框 ...

随机推荐

  1. React16版本的新特性

    React16版本更新的新特性 2018年05月03日 21:27:56 阅读数:188 1.render方法的返回值类型:New render return types 之前的方式: class A ...

  2. 【廖雪峰老师python教程】——OOP

    概述 面向对象编程——Object Oriented Programming,简称OOP,是一种程序设计思想.OOP把对象作为程序的基本单元,一个对象包含了数据和操作数据的函数. 数据封装.继承和多态 ...

  3. mysql 处理日期格式

    DATE_FORMAT(createTime,'%Y-%m-%d %H:%i:%s') 对应格式: 2018-12-17 17:33:43 DATE_FORMAT()函数所有格式:   以后有需要在自 ...

  4. (干货分享)mac python+appium环境搭建

    因为mac本自带python2.x(不建议卸载,因为本本本身有很多依赖与此),所以装python3的过程极其坎坷,勉强装好后也总是各种报错.这次装appium环境,直接把原来的python3卸了,用h ...

  5. 为Zabbix配置RabbitMQ监控模板

    RabbitMQ的配置参考 https://github.com/jasonmcintosh/rabbitmq-zabbix 简而言之,具体分为几个步骤: 1. 将脚本文件(scripts文件夹)和配 ...

  6. 怎么用Q-Q图验证数据集的分布

    样本数据集在构建机器学习模型的过程中具有重要的作用,样本数据集包括训练集.验证集.测试集,其中训练集和验证集的作用是对学习模型进行参数择优,测试集是测试该模型的泛化能力. 正负样本数据集符合独立同分布 ...

  7. Android 之Buletooth

    一:概要: Android提供了Buletooth的API ,通过API 我们可以进行如下的一些操作: 1.扫描其他的蓝牙设备 2.查询能配对的蓝牙设备 3.建立RFCOMM 通道 4.连接其他的蓝牙 ...

  8. 用OneNote写博客的方法

    1.进入OneNote要发布博客的分区然后点击菜单栏中的文件         2.点击发送至博客         3.这时候会启动word程序弹出下面的对话框(如果你从未设置过)点击立即注册     ...

  9. C# 获取方法所在的 命名空间 类名 方法名

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  10. JDBC数据源的驱动问题

    classes12.jar,ojdbc14.jar,ojdbc5.jar和ojdbc6.jar的区别,之间的差异 在使用Oracle JDBC驱动时,有些问题你是不是通过替换不同版本的Oracle  ...