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使用

  • 相关阅读:
    UARTRS232与RS485的关系
    RS-485总线通信协议
    【转】TCP(协议号6)的方方面面
    【转】Android 编程下的代码混淆
    【转】阻塞与非阻塞socket的优缺点
    【转】Socket状态变迁图
    【转】Spring中IoC的优点与缺点
    linux_UAPI_转
    数组初始化
    中兴被制裁:到底对谁说话 13亿人民中1人有话说
  • 原文地址:https://www.cnblogs.com/diegodu/p/7845354.html
Copyright © 2011-2022 走看看