zoukankan      html  css  js  c++  java
  • Spring Bean是什么

      本文介绍一个基本概念—— Spring Bean是什么。

      把Bean理解为类的代理或代言人(实际上确实是通过反射、代理来实现的),这样它就能代表类拥有该拥有的东西了。

      Spring 官方文档对 bean 的定义如下:

    In Spring, the objects that form the backbone of your application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container.

      中文意思就是:

    在 Spring 中,构成应用程序主干并由Spring IoC容器管理的对象称为beans。bean是一个由Spring IoC容器实例化、组装和管理的对象。

      概念简单明了,可以提炼出如下三条关键信息:

    1. bean是对象,数量不限,即可以为多个;
    2. bean由Spring IoC容器管理;
    3. 应用程序由一个个bean构建。

      Spring帮助我们通过两种方式管理bean,一种是注册Bean,另一种是装配Bean。完成管理动作的方式有如下三种:

    1. 使用自动配置。@Component注解及其衍生注解@RestController、@Controller、@Service和@Repository等都是组件注册注解。使用组件注册注解告诉Spring,我是一个bean,你要来管理我,然后使用@AutoWired注解去装配Bean;也可以使用
      由javax.annotation.Resource提供@Resource去装配Bean。所谓装配,就是管理各个对象之间的协作关系。

    2. 使用JavaConfig。使用@Configuration告诉Spring,IoC容器要怎么配置,即怎么去注册bean,怎么去处理bean之间的关系(装配)。

    3. 使用XML配置。标签就是告诉spring怎么获取这个bean,各种就是手动的配置bean之间的关系。


      读后有收获,小礼物走一走,请作者喝咖啡。

    赞赏支持

  • 相关阅读:
    【javascript】手写call,apply,bind函数
    http压缩 Content-Encoding: gzip
    【javascript】强大的CSS3/JS:帧动画的多种实现方式与性能对比
    【canvas】html5 canvas常用api总结(二)--图像变换API
    【canvas】html5 canvas常用api总结(一)--绘图API
    python的列表试用3-6
    UIImagePickerController获取照片的实现,添加overlay方法 (相机取景框)
    调试JDK1.8源码的方法
    多线程-Executor,Executors,ExecutorService,ScheduledExecutorService,AbstractExecutorService
    多线程-Fork/Join
  • 原文地址:https://www.cnblogs.com/east7/p/14390862.html
Copyright © 2011-2022 走看看