zoukankan      html  css  js  c++  java
  • @Bean 和@ Component的区别

    1. @Component auto detects and configures the beans using classpath scanning whereas @Bean explicitly declares a single bean, rather than letting Spring do it automatically.
    2. @Component does not decouple the declaration of the bean from the class definition where as @Bean decouples the declaration of the bean from the class definition.
    3. @Component is a class level annotation where as @Bean is a method level annotation and name of the method serves as the bean name.
    4. @Component need not to be used with the @Configuration annotation where as @Bean annotation has to be used within the class which is annotated with @Configuration.
    5. We cannot create a bean of a class using @Component, if the class is outside spring container whereas we can create a bean of a class using @Bean even if the class is present outside the spring container.
    6. @Component has different specializations like @Controller, @Repository and @Service whereas @Bean has no specializations.

    1. component :  1  利用spring 类路径扫描,

            2. 写在类上,和类定义不分离。 

            3. 不需要配合 @configuration注解

    2. Bean :  .当类不受spring控制的时候,写一个方法,返回某个不受spring控制的类的对象。 这样就能在spring里注入一个bean。

          配合configuration注解

     参考:https://stackoverflow.com/questions/10604298/spring-component-versus-bean       

  • 相关阅读:
    2014最后一篇英语笔记(新开始)
    记录:CSS特殊性——权值规则
    grunt--自动化打包工具使用
    【移动端】---点透事件
    [前端性能提升]--图片转化为base64
    js--cookie
    1.倒数几秒弹窗关闭
    ES6就是ES2015 的主要内容
    call 与 apply的区别
    34枚金币时间管理法
  • 原文地址:https://www.cnblogs.com/lhuser/p/10972833.html
Copyright © 2011-2022 走看看