zoukankan      html  css  js  c++  java
  • Spring中的内部Bean

    简介

    当一个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>
  • 相关阅读:
    ⑤SpringBoot之定时任务
    ④SpringBoot之thymeleaf使用
    ③SpringBoot中Redis的使用
    ②SpringBoot之Web综合开发
    Redis、Memcache和MongoDB
    ADB常用命令 & 无线调试Debug黑科技
    Flutter生命周期
    Flutter-Tips
    Git rebase命令
    Git 恢复本地误删的文件
  • 原文地址:https://www.cnblogs.com/shamo89/p/9917663.html
Copyright © 2011-2022 走看看