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泛指 ...
随机推荐
- Hibernate中的Session缓存问题
1. Session 缓存: 1) . 在 Session 接口的实现中包括一系列的 Java 集合 , 这些 Java 集合构成了 Session 缓存 . 它用于存放 Sessi ...
- intrawebIW当作REST 服务端
intraweb15 该版本支持HTTPS.SYS通信. IW当作REST 服务端使用: procedure TIWServerController.IWServerControllerBaseExe ...
- Windows 8 Metro 应用开发入门(一):开发环境介绍
摘 要 Windows8已经发布,随之而来的基于WinRT的Metro应用也正向我们走来,正像它所宣传的:光滑.快.现代.看习惯了玻璃.立体风格的应用,或许Metro的简洁能给你留下不一样的体验.Vi ...
- 使用开源库 EasyTimeline 操作定时器 NSTimer
EasyTimeline https://github.com/mmislam101/EasyTimeline Sometimes you need things to happen at speci ...
- struts从2.3.X升级到2.5.18中遇到的问题及解决办法
1,2.5.X版本不再提供xwork.jar ,整合到了 struts-core包中.2,需要升级替换的jar文件:commons-langcommons-lang3ognl其他所有struts2开头 ...
- LaTeX中的数学公式
因为想在过年之前把论文写出来(虽然现在看来似乎痴人说梦),用word写PDE的公式简直是自己找虐,就想说自己研究一下LaTex,用起来发现这东西写格式性的文档真心甩word几个陈景润啊,出来的公式不仅 ...
- iOS:UIToolBar、toolbarItems、BarButtonItem的几种关系
工具栏:ToolBar 工具栏项目:Bar Button Item 调节按钮位置的固定调节:Fixed Space Bar Button Item 调节按钮位置的灵活调节:Flexible Space ...
- 混沌数学之ASin模型
相关软件:混沌数学之离散点集图形DEMO 相关代码: class ASinEquation : public DiscreteEquation { public: ASinEquation() { m ...
- 3D屏保:排色榜
3D屏保:排色榜 排色榜,是一个针对图形学中的色彩进行排序的DEMO,这里的色是色彩的意思,看成别的点进来的同学请自觉面壁.该DEMO可以按RGB,GBR,BRG,灰度值四种方式进行排序.排序算法为冒 ...
- python 中面向对象编程的几个概念
Python super() 函数 super() 函数是用于调用父类(超类)的一个方法. super 是用来解决多重继承问题的,直接用类名调用父类方法在使用单继承的时候没问题,但是如果使用多继承,会 ...