zoukankan      html  css  js  c++  java
  • bean容器能力

    bean容器能力

    对bean容器的最简单的述求

    1. 能生产bean
    2. 能注入组装bean: 字段,构造函数

    spring bean容器(3.0版本)的能力列表

    1. 能生产bean
    2. 能注入组装bean:字段,构造函数的参数(可以按参数类型注入-type,也可以按参数位置注入-index,也可以按参数名字注入),调用指定方法(lookup-method)
    3. 能支持生产bean的scope:单例,多例,web请求,web session,ThreadLocal级等
    4. 能引入properties文件作为注入源
    5. 能支持特殊值注入,诸如null,List,Map,Properties等
    6. 能在进行注入之前进行值转换,比如数组转成集合,字符串转成数字,字符串转换成resource
      需要梳理 能支持哪些转换?
      org.springframework.core.convert.converter.Converter<S, T>
      文档参见
    7. 能在进行注入之前进行待条件的值转换,即在满足条件时再触发转换
      org.springframework.core.convert.converter.ConditionalGenericConverter
      文档参见
    8. 支持在进行注入之前进行值格式化,同时支持注解 @NumberFormat @DateTimeFormat等
    9. 支持在进行注入之前进行对值校验, 遵循JSR-303
    10. 能支持 用户定义生产bean 的工厂
    11. 能将bean容器与struts,junit等第三方框架对接,作为其bean的产生实现方式
    12. 容器对接多种规范的容器,诸如servlet容器等
    13. 支持bean查找,属性字段值设置与获取,方法调用,集合元素按index获取,逻辑数学运算,命名变量等能力的表达式(JSP 2.1 specification的一个扩展)
    14. 支持 字段值 来自于表达式
    private @Value("#{jdbcProperties.url}") String jdbcUrl;
    
    1. 兼容 standard JDK PropertyEditors
    2. 支持字段值转换的自定义实现的SPI
    3. 支持生产bean时,触发其方法调用,并可以用注解结合表达式编写声明参数值来源
    @Value("#{systemProperties.databaseName}")
        public void setDatabaseName(String dbName) { … }
    
    1. 支持bean metadata注解式配置:
      Configuration Bean DependsOn Primary Lazy Import ImportResource Value
      Required Autowired Inject Qualifier Resource PostConstruct PreDestroy Service Repository
    2. 支持加了Configuration注解的java类作为容器的描述
    ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
    
    1. 支持容器的描述文件的import能力,比如在一个application-1的xml中import另一个application-2的xml文件
    2. 支持bean的name的别名,多系统协同时可以使用,使得bean的命名清晰
    3. 支持用类的静态方法作为生产该类bean的工厂行为。
    4. 支持用指定类的指定静态方法生产具体bean的行为
      参见文档
    5. 支持声明式properties注入
      jdbc.driver.className=com.mysql.jdbc.Driver
      jdbc.url=jdbc:mysql://localhost:3306/mydb
    6. 用idref或者ref标签配合local使用,可以达到仅使用本容器中的bean进行注入。

    As such, using the local variant is the best choice (in order to know about errors as early as possible) if the target bean is in the same XML file.

    1. 用idref或者ref标签配合parent使用,可以达到仅使用父容器中的bean进行注入
    2. 支持在注入时,声明所需要的属性,类似内部类,此处声明的实例是多实例的且不会被其他人ref(因为没有id和name)
     <bean id="outer" class="...">
    <!-- instead of using a reference to a target bean, simply define the target bean inline -->
    <property name="target">
      <bean class="com.example.Person"> <!-- this is the inner bean -->
        <property name="name" value="Fiona Apple"/>
        <property name="age" value="25"/>
      </bean>
    </property>
    </bean>
    
    1. 支持复合属性注入,如对bean的属性字段的子字段进行注入,比如需要主要实例a的字段b是B类型,Bclass有个c字段,那么可以注入a时直接给b的c字段注入。

    2. 支持显示声明(描述) bean的依赖,比如a depends-on b,那么在a构造前 会先把b构造好。主要用于一些静态初始化等,诸如数据库的驱动注册。

    3. 对于单例bean,支持可选的初始化阶段:容器启动时和bean被用到时。可以用lazy-init标识一个单例bean在被用到时再初始化bean。默认行为是容器启动时初始化bean,因为这样要是缺了什么bean就能立即通过错误知道。

    4. 支持整个容器级别的默认延迟初始化行为设置

    5. 支持按name,按type自动装配

    6. 支持bean和beans粒度的自动装配关闭autowire-candidate

    7. 支持bean的普通方法在调用时 用 replaced-method替换入参值 。 待做个demo。

    8. 支持自定义容器中bean的生命周期
      org.springframework.beans.factory.config.Scope

    9. 支持容器生命周期的回调动作插入 afterPropertiesSet(容器注入完成后的回调) init-method(bean的初始化方法) destroy-method(bean销毁时的方法) 容器关闭hook注册 支持bean和beans级别设置

    10. 按层级(inheritance)描述bean容器中bean定义。bean a是父实例是抽象的,bean b是子实例,可以将其parent指向bean a,使用bean a的所有配置信息,包括注入的属性字段等等,也可以覆盖字段。而且父实例bean a可以不用指向任何class,只需要设置其abstract为true即可。

    11. bean容器自身支持扩展点 BeanPostProcessor(postProcessBeforeInitialization,postProcessAfterInitialization)
      这个值得一看,自身就有很多实现。
      BeanFactoryPostProcessor(postProcessBeanFactory)

    12. 支持bean的id分类

    13. 自动装配的component-scan扫描支持include和exclude的filter

    14. 支持国际化能力 ResourceBundleMessageSource

    15. 容器内建事件支持 ContextRefreshedEvent ContextStartedEvent ContextStoppedEvent ContextClosedEvent RequestHandledEvent

    16. 自定义容器事件支持ApplicationEvent

    spring DM能力列表

    1. OSGI bundle的三种状态支持 installed, resolved, starting,stopping,uninstalled or active(OSGI能力)
    2. 隔离业务逻辑到模块中,在运行期强制模块化(OSGI能力)
    3. 多版本模块或者库并存(OSGI能力)
    4. 运行时,动态安装升级与卸载(OSGI能力)
    5. spring dm应用结构示意图
    6. 用osgi:service 标签支持接口暴露
    7. 定制支持OSGI的IO能力
    8. 支持bundle级别的scope
    9. 用service与interfaces标签配合使用 将一个bean注册为多个接口的实现
    10. registration-listener支持注册监听器 也有去注册监听器
    11. reference标签支持接口引用
  • 相关阅读:
    JavaWeb图片显示与存储
    sql将日期按照年月分组并统计数量
    response的作用
    TCP/IP学习笔记(1)-----基本概念
    TCP/IP学习笔记(2)---数据链路层
    TCP/IP学习笔记(3)----IP,ARP,RARP协议
    TCP/IP学习笔记(4)------ICMP,ping,traceroute
    TCP/IP学习笔记(5)------IP选路
    如何运行简单的scrapy
    difference among String,StringBuilder,StringBuffer
  • 原文地址:https://www.cnblogs.com/simoncook/p/8017505.html
Copyright © 2011-2022 走看看