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

  • 相关阅读:
    《ASP.NET Core项目开发实战入门》带你走进ASP.NET Core开发
    网络监控工具 iftop dstat
    可进行组合的枚举
    查看Qt自带的QSS
    通过文件设置QSS
    QString转QByteArray
    error: jump to case label
    error: static member function cannot have cv-qualifier
    C++ std::vector的大小和容量
    获取QMessageBox返回值
  • 原文地址:https://www.cnblogs.com/diegodu/p/7845354.html
Copyright © 2011-2022 走看看