zoukankan      html  css  js  c++  java
  • Spring点滴二:Spring Bean

    Spring Bean:

       被称作bean的对象是构成应用程序的支柱,是由Spring Ioc容器管理。bean是一个被实例化,配置、组装并由Spring Ioc容器管理对象。

       官网API:A Spring IoC container manages one or more beans. These beans are created with the configuration metadata that you supply to the container, for example, in the form of XML <bean/> definitions.

       翻译:一个Spring IoC容器管理一个或多个beans。这些benas的创建是由配置元数据提供到容器里。例如:XML 表单中<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.xsd">
        <!-- 定义一个bean -->
        <bean id="...." class="....">
        </bean>
    </beans>

    <bean>标签包含属性详解:

     id/name  用来指定bean唯一标识符,在基于XML配置元数据中,通过id或那么来指定bean唯一标识符    
     class  该属性是强制性的,用来指定bean所对应的Java POJO类
     scope  用来指定bean对象的作用域
     constructor-arg  用来注入依赖关系的
     properties  用来注入依赖关系的
     autowiring mode  用来注入依赖关系的
     lazy-initialization mode  该bean是延迟初始化的,告诉Spring容器该bean不是在容器启动时初始化的而是第一次被请求时才初始化
     initialization 方法  该bean被初始化时要调用的方法
     destruction 方法  该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.xsd">
    
       <!-- A simple bean definition -->
       <bean id="..." class="...">
           <!-- collaborators and configuration for this bean go here -->
       </bean>
    
       <!-- A bean definition with lazy init set on -->
       <bean id="..." class="..." lazy-init="true">
           <!-- collaborators and configuration for this bean go here -->
       </bean>
    
       <!-- A bean definition with initialization method -->
       <bean id="..." class="..." init-method="...">
           <!-- collaborators and configuration for this bean go here -->
       </bean>
    
       <!-- A bean definition with destruction method -->
       <bean id="..." class="..." destroy-method="...">
           <!-- collaborators and configuration for this bean go here -->
       </bean>
    
       <!-- more bean definitions go here -->
    
    </beans>

       

  • 相关阅读:
    hdu 5936 2016ccpc 杭州
    bzoj 1218: [HNOI2003]激光炸弹
    bzoj 1296: [SCOI2009]粉刷匠
    桃子到底有多少
    计算x的n次方
    计算x的n次方
    菲波拉契数列
    菲波拉契数列
    八皇后(N皇后)问题算法程序(回溯法)
    八皇后(N皇后)问题算法程序(回溯法)
  • 原文地址:https://www.cnblogs.com/sishang/p/6565546.html
Copyright © 2011-2022 走看看