zoukankan      html  css  js  c++  java
  • component和bean区别

    @Component and @Bean do two quite different things, and shouldn't be confused.

    @Component (and @Service and @Repository) are used to auto-detect and auto-configure beans using classpath scanning. There's an implicit one-to-one mapping between the annotated class and the bean (i.e. one bean per class). Control of wiring is quite limited with this approach, since it's purely declarative.

    @Bean is used to explicitly declare a single bean, rather than letting Spring do it automatically as above. It decouples the declaration of the bean from the class definition, and lets you create and configure beans exactly how you choose.

    @COMPONENT

    If we mark a class with @Component or one of the other Stereotype annotations these classes will be auto-detected using classpath scanning. As long as these classes are in under our base package or Spring is aware of another package to scan, a new bean will be created for each of these classes. 

    @BEAN

    @Bean is used to explicitly declare a single bean, rather than letting Spring do it automatically like we did with @Controller. It decouples the declaration of the bean from the class definition and lets you create and configure beans exactly how you choose.

    Componet 一般放在类上面,Bean放在方法上面,自己可控制是否生成bean

    bean 一般会放在classpath scanning路径下面,会自动生成bean

    有Componet /bean生成的bean都提供给autowire使用

  • 相关阅读:
    SPSS时间序列:频谱分析
    PureBasic—数控编辑框与调节块和进度条
    DELPHI2007 安装ACTIVEX插件的方法
    C++ builder的文件操作
    C++动态数组
    excel快速复制大量公式的方法
    Delphi XE5 如何与其他版本共存
    PureBasic 集成Form设计器的使用
    VS C++ 从一个窗口创建另一个窗口
    ENVI 5.0 Beta 体验——影像数据的显示
  • 原文地址:https://www.cnblogs.com/diegodu/p/7845354.html
Copyright © 2011-2022 走看看