@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/>的功能,但 ...
随机推荐
- window golang1.12.4 安装配置&IDE vscode
step 1:下载golang golang官网地址是 https://golang.org/dl/ 如果没有墙的话,可以用这个地址 https://golang.google.cn/dl/ 如图: ...
- 玲珑杯 Round #5 Problem E Tetration (枚举 + 欧拉公式)
题目链接 Tetration 题意 给定一个排列 现在可以任意调整这个排列的顺序 求$a_{1}^{a_{2}^{a_{3}^{...^{a_{n}}}}}$对$p$取模的最小值 直接枚举$a$ ...
- Java微信开发以及对各种云的评价
目前一个人用Java开发一个微信的会员系统,开发已经结束,现在进入测试阶段. 有一些时间看看市面上的一些Java的微信开发视频,看了一下北风网的<微信公众平台开发Java版第一季>中的1, ...
- Idea下Maven的使用
一.导入maven结构的web工程 (1)在Intellij IDEA中选择File->New->Project from Version Control->Subversion. ...
- iOS 汉字转拼音 PinYin4Objc
PinYin4Objc 是一个效率很高的汉字转拼音类库,支持简体和繁体中文.有以下特性:1.效率高,使用数据缓存,第一次初始化以后,拼音数据存入文件缓存和内存缓存,后面转换效率大大提高:2.支持自定义 ...
- http://blog.csdn.net/LANGXINLEN/article/details/50421988
GitHub上史上最全的Android开源项目分类汇总 今天在看博客的时候,无意中发现了 @Trinea在GitHub上的一个项目 Android开源项目分类汇总, 由于类容太多了,我没有一个个完整地 ...
- 2016.6.20 eclipse安装完毕后打开失败,显示a JDK or a JRE must be avaliable in order to run Eclispe
下载完成后,点击eclipse.exe,跳出如下错误. 按照百度的方法,修改了一下eclispe的配置文件,不仅没解决问题,结果跳出另一个新的错误: Failed to load the JNI sh ...
- vue2.0 仿手机新闻站(五)全局的 loading 组件
1.组件结构 index.js const LoadingComponent = require('./Loading.vue') const loading = { install: functio ...
- iptables和DNS
1.iptables防火墙 表→链→规则 filter表 数据过滤表 NAT表---内网和外网的地址转换 Mangle-----数据流量,通过防火墙设置流量.特殊数据包标记.太复杂,一般不用.限速工具 ...
- JSBridge深度剖析
概述 做过混合开发的人都知道Ionic和PhoneGap之类的框架,这些框架在web基础上包装一层Native.然后通过Bridge技术的js调用本地的库. 在讲JSBridge技术之前.我们来看一下 ...