简介

当一个bean仅被用作另一个bean的属性时,它能被声明为一个内部bean,为了定义inner bean,在Spring 的 基于XML的 配置元数据中,可以在 <property/>或 <constructor-arg/> 元素内使用<bean/> 元素,内部bean通常是匿名的,它们的Scope一般是prototype。

代码示例

<?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.xsd"> <bean id="person2" class="com.itdjx.spring.dependency.injection.Person">
<property name="name" value="李玉"/>
<property name="age" value="23"/>
<property name="sex" value="女"/>
<property name="car" >
<bean class="com.itdjx.spring.dependency.injection.Car">
<constructor-arg value="Ferrari" index="0"/>
<constructor-arg value="Italy" index="1"/>
<constructor-arg value="22500000" type="double"/>
</bean>
</property>
</bean> </beans>

Spring中的内部Bean的更多相关文章

  1. Spring中常见的bean创建异常

    Spring中常见的bean创建异常 1. 概述     本次我们将讨论在spring中BeanFactory创建bean实例时经常遇到的异常 org.springframework.beans.fa ...

  2. 【转】Spring 中三种Bean配置方式比较

    今天被问到Spring中Bean的配置方式,很尴尬,只想到了基于XML的配置方式,其他的一时想不起来了,看来Spring的内容还没有完全梳理清楚,见到一篇不错的文章,就先转过来了. 以前Java框架基 ...

  3. Spring 中三种Bean配置方式比较

    今天被问到Spring中Bean的配置方式,很尴尬,只想到了基于XML的配置方式,其他的一时想不起来了,看来Spring的内容还没有完全梳理清楚,见到一篇不错的文章,就先转过来了. 以前Java框架基 ...

  4. Spring的引用内部Bean属性和给级联属性

    第一个是内部Bean的配置:               首先是要理解其中的原理,再去操作就很简单了,下面老表就给大家说一下自己的观点(有点简单,但是老表我第一次学习的时候看着视频上的代码确实有点懵逼 ...

  5. Spring中如何向 Bean注入系统属性或环境变量

    [转自] http://unmi.cc/spring-injection-system-properties-env/ 在 Spring 中为 javabean 注入属性文件中的属性值一般人都知道的, ...

  6. spring中自动装配bean

    首先用@Component注解类: package soundsystem: import org.springframework.stereotype.Component; @Component p ...

  7. Spring中注解注入bean和配置文件注入bean

    注解的方式确实比手动写xml文件注入要方便快捷很多,省去了很多不必要的时间去写xml文件 按以往要注入bean的时候,需要去配置一个xml,当然也可以直接扫描包体,用xml注入bean有以下方法: & ...

  8. Spring中@Component与@Bean的区别

    @Component和@Bean的目的是一样的,都是注册bean到Spring容器中. @Component  VS  @Bean @Component 和 它的子类型(@Controller, @S ...

  9. 半夜思考之查漏补缺, 在 Spring中, 所有的 bean 都是 Spring 创建的吗 ?

    Spring 是一个 bean 容器, 负责 bean 的创建, 那么所有的 bean对象都是 Spring 容器创建的吗 ? 答案是否定的. 但是乍一想, 好像所有的对象都是 Spring 容器负责 ...

随机推荐

  1. uva 213 - Message Decoding (我认为我的方法要比书上少非常多代码,不保证好……)

    #include<stdio.h> #include<math.h> #include<string.h> char s[250]; char a[10][250] ...

  2. SpringBoot四大神器之Starter

    SpringBoot的starter主要用来简化依赖用的.本文主要分两部分,一部分是列出一些starter的依赖,另一部分是教你自己写一个starter. 部分starters的依赖 Starter( ...

  3. 【React全家桶入门之十三】Redux中间件与异步action

    在上一篇中我们了解到,更新Redux中状态的流程是这种:action -> reducer -> new state. 文中也讲到.action是一个普通的javascript对象.red ...

  4. Android中startService的使用及Service生命周期

    Android中有两种主要方式使用Service,通过调用Context的startService方法或调用Context的bindService方法.本文仅仅探讨纯startService的使用.不 ...

  5. 在 linux 下使用 CMake 构建应用程序

    学习cmake http://xwz.me/wiki/doku.php?id=cmake 碰到的一些问题: 1.You have changed variables that require your ...

  6. sublime Text3 JsFormat

    https://github.com/sprinng/JsFormat 下载解压 放到 首选项 --> 浏览插件目录 重启sublime ctrl+shift+p 安装 使用: 右键JsForm ...

  7. js-知识集锦

      CreateTime--2016年9月22日14:37:51Author:Marydonjs小知识点集锦1. JSON.stringify(Obj);//将Object对象转换成json格式的st ...

  8. python之函数用法vars()

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法vars() #vars() #说明:返回对象object的属性和属性值的字典对象 ' ...

  9. Java典型应用彻查1000例:图形与网络游戏开发 PDF 扫描版[68M]

    <Java典型应用彻查1000例·图形与网络游戏开发>实例丰富,编排合理,可以让有初级Java基础的读者,从陌生到完全熟练地设计网络游戏,进而掌握3D立体绘图方法,适合作为Java网络游戏 ...

  10. Drupal Form问题汇总

    问:如何校验和提交表单?答:Drupal允许定义默认的表单校验处理函数和提交处理函数. function practice_demo_form($form, &$form_state) { . ...