@Bean 和@ Component的区别
- @Component auto detects and configures the beans using classpath scanning whereas @Bean explicitly declares a single bean, rather than letting Spring do it automatically.
- @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.
- @Component is a class level annotation where as @Bean is a method level annotation and name of the method serves as the bean name.
- @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.
- 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.
- @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的区别的更多相关文章
- 关于 Spring Boot 中创建对象的疑虑 → @Bean 与 @Component 同时作用同一个类,会怎么样?
开心一刻 今天放学回家,气愤愤地找到我妈 我:妈,我们班同学都说我五官长得特别平 妈:你小时候爱趴着睡觉 我:你怎么不把我翻过来呢 妈:那你不是凌晨2点时候出生的吗 我:嗯,凌晨2点出生就爱趴着睡觉呗 ...
- React.createClass和extends Component的区别
React.createClass和extends Component的区别主要在于: 语法区别 propType 和 getDefaultProps 状态的区别 this区别 Mixins 语法区别 ...
- spring boot --- 注解 @Bean 和@Component
1.前言 @Bean是给方法注册bean @Component是给不好归类的类注册bean 2.可以达到一样的效果 (1)@Component 直接注册即可 完整源码 package com.exam ...
- Java BEAN与EJB的区别
Java Bean 是可复用的组件,对Java Bean并没有严格的规范,理论上讲,任何一个Java类都可以是一个Bean.但通常情况下,由于Java Bean是被容器所创建(如Tomcat)的,所以 ...
- angular5 directive和component的区别
指令分为三类,组件,属性指令和结构性指令 组件(Component directive):UI组件,继承于Directive: 属性指令(Attribute directive):改变组件的样式: 结 ...
- vue.extend与vue.component的区别和联系
一味的闷头开发,却对基础概念缺乏理解,是个大坑... 查阅官网后现对自己的理解记录一下,用于日后复习巩固 Vue.extend({}) 简述:使用vue.extend返回一个子类构造函数,也就是预设部 ...
- vue.extend和vue.component的区别
vue.extend 使用基础 Vue 构造器函数,通过原型继承,(返回)创建一个"子类"(构造器).参数是一个包含组件选项的对象. const Sub = function Vu ...
- 注解装配Bean
@Service用于标注业务层组件@Controller用于标注控制层组件@Repository用于标注数据访问组件,即DAO组件@Component泛指组件,当组件不好归类的时候,我们可以使用这个注 ...
- @Bean和@Componet区别
无意在两个类上看到了这两个注解,一个使用了@Bean配合@Configuration,一个使用了@Componet.依稀记得这两个注解都是实现以前在xml中<bean xxx/>的功能,但 ...
随机推荐
- docker下使用DB2
1.查询可安装的db2镜像 benjamin@docker:~$ docker images |grep -i db2 ibmcom/db2express-c latest 7aa154d9b73c ...
- hdu 4520
小Q系列故事——最佳裁判 Time Limit: 500/200 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...
- hdu 1215(因子和)
七夕节 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- 关于TP中U方法,在wamp中是绝对路径,在nginx中是相对路径?(坑)
这个问题已多次遇到,关于tp 框架 使用U 方法跳转, 在Nginx 服务器上可能会遇到路由跳转不过去前面带点(如:./xx) 解决这个问题,可以在tp的入口文件 index.php 里定义个常量 d ...
- 洛谷 P1579 哥德巴赫猜想(升级版)【筛素数/技巧性枚举/易错】
[链接]:https://www.luogu.org/problemnew/show/P1579 题目背景 1742年6月7日哥德巴赫写信给当时的大数学家欧拉,正式提出了以下的猜想:任何一个大于9的奇 ...
- 洛谷—— P2417 课程
https://www.luogu.org/problemnew/show/2417 题目描述 n个学生去p个课堂,每一个学生都有自己的课堂,并且每个学生只能去一个课堂,题目要求能够安排每一个课堂都有 ...
- codevs——1267 老鼠的旅行(棋盘DP)
1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description ...
- XCode删除多余的Simulator(模拟器)
每个xocde都会自带一个模拟器,且都是随安装包一起打包的,比如xcode8.0的就自带iOS10的模拟器,这个是没办法删除. 但是对于想要用iOS10以前的模拟器,可以通过这里进行下载: 最终下载的 ...
- 如何限制Dedecms文章或产品描述的字数
在Dedecms系统中,文章摘要(可以通过infolen或description相关标签调用)被设置了字数上限为250字符,设置上限的主要目的是减少数据库的冗余,保证网站良好的性能.因此,如果对简介内 ...
- wxWidgets界面开发工具wxFormBuilder的使用
wxFormBuilder 下载地址:http://download.csdn.net/detail/lsmallstop/7013401 安装完成后,打开wxFormBuilder,可以在左侧工程子 ...