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使用
component和bean区别的更多相关文章
- [转载]@Component 和 @Bean 的区别
@Component 和 @Bean 的区别 @Component 和 @Bean 的区别 Spring帮助我们管理Bean分为两个部分,一个是注册Bean,一个装配Bean. 完成这两个动作有三种方 ...
- @component @bean区别
from: http://stackoverflow.com/questions/10604298/spring-component-versus-bean http://stackoverflow. ...
- Spring中@Component与@Bean的区别
@Component和@Bean的目的是一样的,都是注册bean到Spring容器中. @Component VS @Bean @Component 和 它的子类型(@Controller, @S ...
- Spring中<ref local=""/>与<ref bean=""/>区别
小 Spring中<ref local=""/>与<ref bean=""/>区别 (2011-03-19 19:21:58) 转载▼ ...
- @Component 和 @Bean 的区别
Spring帮助我们管理Bean分为两个部分,一个是注册Bean,一个装配Bean.完成这两个动作有三种方式,一种是使用自动配置的方式.一种是使用JavaConfig的方式,一种就是使用XML配置的方 ...
- @Component和@Bean以及@Autowired、@Resource
1. 有这么一个故事,从xml配置文件的bean说起 Spring用xml配置文件的时候(不知道阅读这篇文章的你用没用过,我用过一段时间,那是黑暗伤痛的回忆QQQ),一个xml配置文件里面有很多个 ...
- @configuration和@component之间的区别
@configuration和@component之间的区别是:@Component注解的范围最广,所有类都可以注解,但是@Configuration注解一般注解在这样的类上:这个类里面有@Value ...
- Spring中ref local与ref bean区别
今天在做SSH框架Demo实例时,在ApplicationResources.properties文件时对<ref bean>与<ref local>感到不解,经查找资料才弄明 ...
- Spring中的注解@Service @Component @Controller @Repository区别
@Service用于标注业务层组件, @Controller用于标注控制层组件(如struts中的action), @Repository用于标注数据访问组件,即DAO组件, @Component泛指 ...
随机推荐
- C# 标签(条码)的打印与设计(二)
上一篇说到条码的打印,主要是通过读取模板定义文件(XML文件),然后结合从数据库中读取的动态数据结合而产生条码.下面主要说一下如何设计这个条码模板.设计过程也很简单,只需要简单的拖拉即可.然后点击小箭 ...
- SAE java应用读写文件(TmpFS和Storage)
近期不少java用户都在提sae读写本地文件的问题,在这里结合TmpFS和Storage服务说说java应用应该如何读写文件TmpFS是一个供应用临时读写的路径,但请求过后将被销毁.出于安全考虑,sa ...
- [部署Mantis]用Administrator注册新用户时设置密码
伤不起的Mantis邮箱配置,在新的Mantis配置里面默认通过接收激活邮件来设定密码. 如果你Mantis邮箱配置OK的话一切OK,遇到我这样死活配不成功,网络上大神们众说纷纭,一一参照,无奈死伤无 ...
- Android只播放gif动画
使用easygifanimator软件把gif动画打散为图片. 第一步:先上图片素材,以下素材放到res/drawable目录下: 转:http://blog.csdn.net/aminfo/arti ...
- [Git] 谷歌的代码管理
copy from : http://www.ruanyifeng.com/blog/2016/07/google-monolithic-source-repository.html https:// ...
- 【BZOJ】【2946】【POI2000】公共串
后缀数组 好感动,复习了下后缀数组居然写出来了……(感谢ykz大神) 求最长公共子串……WA了一发是因为:[不同字符串之间要用不同的特殊字符隔开]否则就会匹配到相同→_→比如都是aaa结尾,如果用相同 ...
- php扩展开发笔记(2)多个源代码文件的配置和编译
我们在开发过程中,为了代码得可读性和易维护性,肯定是须要多个代码文件的,而不不过通过 ext_skel 生成得骨架文件. 这篇文章主要介绍下.多个代码文件的时候.我们须要注意什么,以及怎么做. 我的代 ...
- 开启hadoop和Hbase集群的lzo压缩功能(转)
原文链接:开启hadoop和Hbase集群的lzo压缩功能 问题导读: 1.如何启动hadoop.hbase集群的压缩功能? 2.lzo的作用是什么? 3.hadoop配置文件需要做哪些修改? 首先我 ...
- 第十一章 自己实现一致性hash算法
关于一致性hash算法的意义以及其相对于简单求余法(除数求余法)的好处,查看第六章 memcached剖析 注意:真实的hash环的数据结构是二叉树,这里为了简便使用了列表List 1.一致性hash ...
- WF4.0(2)----设计工作流
自从做了程序员,发现自己长胖了,而且自己的身体抵抗力也出了问题,最近身体不适,公司工作任务最近也很赶,上次写了WF4.0的简介,这次就工作中工作流设计的几种方式稍微总结一下.设计工作流包括四种方式:流 ...