• Spring Bean


    Bean定义

    bean 是一个被实例化,组装,并通过 Spring IoC 容器所管理的对象。这些 bean 是由IOC容器读取Bean的配置元数据创建的。

    Bean属性

    <?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="..." class="..." scope="...">
           <!--  -->
       </bean>
    
       <bean id="..." class="..." lazy-init="true">
           <!--  -->
       </bean>
    
       <bean id="..." class="..." init-method="...">
           <!--  -->
       </bean>
    
       <bean id="..." class="..." destroy-method="...">
           <!--  -->
       </bean>
    
       <!-- 其他配置 -->
    
    </beans>

    Bean 与Spring容器关系

    Spring 配置元数据

    Spring IoC 容器完全由实际编写的配置元数据的格式解耦。有下面三个重要的方法把配置元数据提供给 Spring 容器:

    • 基于 XML 的配置文件
    • 基于注解的配置
    • 基于 Java 的配置

    Bean 的作用域

    Bean 的生命周期

    Bean的生命周期可以表达为:Bean的定义——Bean的初始化——Bean的使用——Bean的销毁

    Bean 继承

    bean 定义可以包含很多的配置信息,包括构造函数的参数,属性值,容器的具体信息例如初始化方法,静态工厂方法名,等等。

    子 bean 的定义继承父定义的配置数据。子定义可以根据需要重写一些值,或者添加其他值。

    Spring Bean 定义的继承与 Java 类的继承无关,但是继承的概念是一样的。你可以定义一个父 bean 的定义作为模板和其他子 bean 就可以从父 bean 中继承所需的配置。

    <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="helloWorld" class="com.xxx.xxx.HelloWorld">
          <property name="message1" value="Hello World!"/>
          <property name="message2" value="Hello Second World!"/>
       </bean>
    
       <bean id="helloWorldC" class="com.xxx.xxx.HelloWorldC" parent="helloWorld">
          <property name="message1" value="Hello!"/>
          <property name="message3" value="Children India!"/>
       </bean>
    
    </beans>

    https://zhuanlan.zhihu.com/p/68818095

  • 相关阅读:
    SQL SERVER 2012 第三章 使用INSERT语句添加数据
    SQL SERVER 2012 第三章 T-SQL 基本语句 having子句
    T4 模板生产 多文件
    RAC+DG修改sys密码
    数据泵导入,报错:ORA-12899: value too large for column "SCOTT"."TEST112"."JOIN" (actual: 9, maximum: 8)
    grep过滤空行和注释行
    char与varchar2字符类型的区别
    Oracle不知道用户密码情况下,如何在不更改密码的前提下解锁用户或者延期密码有效期
    数据泵导出报错ORA-31693 ORA-02354 ORA-01466
    安装ogg软件报错:[INS-75012]Sofware Location specified is already an existing Oracle
  • 原文地址:https://www.cnblogs.com/feng9exe/p/11214544.html
Copyright © 2020-2023  润新知