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       

@Bean 和@ Component的区别的更多相关文章

  1. 关于 Spring Boot 中创建对象的疑虑 → @Bean 与 @Component 同时作用同一个类,会怎么样?

    开心一刻 今天放学回家,气愤愤地找到我妈 我:妈,我们班同学都说我五官长得特别平 妈:你小时候爱趴着睡觉 我:你怎么不把我翻过来呢 妈:那你不是凌晨2点时候出生的吗 我:嗯,凌晨2点出生就爱趴着睡觉呗 ...

  2. React.createClass和extends Component的区别

    React.createClass和extends Component的区别主要在于: 语法区别 propType 和 getDefaultProps 状态的区别 this区别 Mixins 语法区别 ...

  3. spring boot --- 注解 @Bean 和@Component

    1.前言 @Bean是给方法注册bean @Component是给不好归类的类注册bean 2.可以达到一样的效果 (1)@Component 直接注册即可 完整源码 package com.exam ...

  4. Java BEAN与EJB的区别

    Java Bean 是可复用的组件,对Java Bean并没有严格的规范,理论上讲,任何一个Java类都可以是一个Bean.但通常情况下,由于Java Bean是被容器所创建(如Tomcat)的,所以 ...

  5. angular5 directive和component的区别

    指令分为三类,组件,属性指令和结构性指令 组件(Component directive):UI组件,继承于Directive: 属性指令(Attribute directive):改变组件的样式: 结 ...

  6. vue.extend与vue.component的区别和联系

    一味的闷头开发,却对基础概念缺乏理解,是个大坑... 查阅官网后现对自己的理解记录一下,用于日后复习巩固 Vue.extend({}) 简述:使用vue.extend返回一个子类构造函数,也就是预设部 ...

  7. vue.extend和vue.component的区别

    vue.extend 使用基础 Vue 构造器函数,通过原型继承,(返回)创建一个"子类"(构造器).参数是一个包含组件选项的对象. const Sub = function Vu ...

  8. 注解装配Bean

    @Service用于标注业务层组件@Controller用于标注控制层组件@Repository用于标注数据访问组件,即DAO组件@Component泛指组件,当组件不好归类的时候,我们可以使用这个注 ...

  9. @Bean和@Componet区别

    无意在两个类上看到了这两个注解,一个使用了@Bean配合@Configuration,一个使用了@Componet.依稀记得这两个注解都是实现以前在xml中<bean xxx/>的功能,但 ...

随机推荐

  1. LeetCode OJ-- Linked List Cycle II **

    https://oj.leetcode.com/problems/linked-list-cycle-ii/ 判断一个链表中是否有环,如果有,求环的开始位置. 按照上道题目的想法,先判断出是否有环来, ...

  2. Smpt命令顺序不正确。 服务器响应为: Error: need EHLO and AUTH first !

    刚发现以前做的QQ邮箱发送邮件不能用了,查找了下原因:未加( EnableSsl  SSL加密连接 )导致的,顿时觉得很坑,以前QQ邮箱也没有这个限制啊,可能是最近加的. 好吧不多说直接从头走起,照顾 ...

  3. Codeforces Gym101473 A.Zero or One (2013-2014 ACM-ICPC Brazil Subregional Programming Contest)

    代码: #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #i ...

  4. POJ 3249 Test for Job (dfs + dp)

    题目链接:http://poj.org/problem?id=3249 题意: 给你一个DAG图,问你入度为0的点到出度为0的点的最长路是多少 思路: 记忆化搜索,注意v[i]可以是负的,所以初始值要 ...

  5. 2016北京集训测试赛(九)Problem C: 狂飙突进的幻想乡

    Solution 我们发现, 对于一条路径来说, 花费总时间为\(ap + q\), 其中\(p\)和\(q\)为定值. 对于每个点, 我们有多条路径可以到达, 因此对于每个区间中的\(a\)我们可以 ...

  6. Tmux常用快捷键及命令

    Exported from workflowy! tmux session start/create session- tmux- tmux new-session -s portage listin ...

  7. [深入浅出iOS库]之数据库 sqlite

    一,sqlite 简介 前面写了一篇博文讲如何在 C# 中使用 ADO 访问各种数据库,在移动开发和嵌入式领域也有一个轻量级的开源关系型数据库-sqlite.它的特点是零配置(无需服务器),单磁盘文件 ...

  8. 解决 java.sql.SQLException: Before start of result set

    java中使用如下代码做数据库连接,用以查询数据 *******************我是分割线************************************* try { Class.f ...

  9. jQuery ajax 获取信息展示在“下拉列表”中

    <link href="${ctxStatic}/jquery-select2/4.0.3/select2.min.css" rel="stylesheet&quo ...

  10. 导出excel(利用工具类导出excel)

    /** * 添加导出功能 * @param creditPageResult * @param request * @param response */ @RequestMapping(value = ...