Bean
作用:用于把当前方法的返回值作为bean对象存入spring的ioc容器中
属性:
name:用于指定bean的id。当不写时,默认值是当前方法的名称
细节:
当我们使用注解配置方法时,如果方法有参数,spring框架会去容器中查找有没有可用的bean对象。
查找的方式和Autowired注解的作用是一样的

列子:

@Bean(name="runner")
@Scope("prototype")
public QueryRunner createQueryRunner(@Qualifier("ds2") DataSource dataSource){//Qualifier用于autowired多个相同类型时return new QueryRunner(dataSource);
}

等同于

<bean id="runner" class="org.apache.commons.dbutils.QueryRunner" scope="prototype">
<!--注入数据源-->
<constructor-arg name="ds" ref="dataSource"></constructor-arg>
</bean>

Spring @Bean @Scope @Qualifier相关推荐

  1. spring bean scope作用域及多线程安全问题场景分析

    2019独角兽企业重金招聘Python工程师标准>>> Scope作用域 在 Spring IoC 容器中具有以下几种作用域: singleton:单例模式,在整个Spring Io ...

  2. Spring bean - scope详解

    ​ Scope是定义Spring如何创建bean的实例的. 在创建bean的时候可以带上scope属性,scope有下面几种类型. Singleton 这也是Spring默认的scope,表示Spri ...

  3. Spring Bean Scope 有状态的Bean 无状态的Bean

    在Spring的Bean配置中,存在这样两种情况: [xhtml] view plaincopy <bean id="testManager" class="com ...

  4. 一分钟弄懂Spring @Bean @Autowired @Qualifier 的常见异常 以及命名规范

    情况1:创建的bean类型和自动装配字段的类型不同-[此操作无效] @Autowired BCryptPasswordEncoder passwordEncoder;@Bean PasswordEnc ...

  5. spring bean属性scope

    ‍‍<bean id="role" class="spring.chapter2.maryGame.Role" scope="singleton ...

  6. Spring Bean 的scope什么时候设置为prototype,什么时候设置为singleton

    Java代码   <bean id = "testAction" class = "com.kewen.xxxAction" scope = " ...

  7. Spring Bean 的 scope属性为何要设置为prototype

    <bean id = "testAction" class = "com.kewen.xxxAction" scope = "prototype ...

  8. spring bean作用域_Spring面试知识点,这是我见过最全面的 - 知识铺

    知识铺: 致力于打造轻知识点,持续更新每次的知识点较少,阅读不累.不占太多时间,不停地来唤醒记忆深处的知识点. Q1.什么是Spring框架? Spring是最流行的企业应用程序框架之一.Spring ...

  9. Spring(3)——装配 Spring Bean 详解

    装配 Bean 的概述 前面已经介绍了 Spring IoC 的理念和设计,这一篇文章将介绍的是如何将自己开发的 Bean 装配到 Spring IoC 容器中. 大部分场景下,我们都会使用 Appl ...

最新文章

  1. 【Linux探索之旅】第二部分第五课:用户和权限,有权就任性
  2. leetcode—Valid Parentheses
  3. 二分于最大流之间的关系
  4. java五子棋用到的类_JAVA五子棋用到的知识点以及方法类有哪些?
  5. eclipse mysql5.7_MySQL5.7、Navicate、jdk、Tomcat、eclipse全套配置及安装(win10)-Go语言中文社区...
  6. python华为面试题10个人数3获取下标
  7. elasticsearch Java API 之Delete By Query API
  8. linux/bsd四大防火墙我们选择谁
  9. leetcode 144. Binary Tree Preorder Traversal ----- java
  10. git rebase基础
  11. CodeForces - 982C Cut 'em all!
  12. jpeg 转rgb c 语言_威刚推出SE770G移动固态硬盘 主打高速传输和RGB灯效
  13. 关于Meminfo中MemAvailable 理解
  14. Sql取出各科分数前三名的学生,Sql各科成绩前三的学生
  15. AI上推荐 之 隐语义模型(LFM)和矩阵分解(MF)
  16. 用各种编程语言写七夕情书
  17. erp系统的开发工具
  18. 深圳大学丽湖校区iPad连校园网WiFi
  19. 灰度图转换成彩色图和彩虹图
  20. Vue3 使用moment进行时间转换

热门文章

  1. 在网站中使用Cookie的简单例子
  2. 120 -算法 - 枚举 数学类 4138:质数的和与积
  3. mysql 加入系统服务_添加Mysql到Windows系统服务
  4. C语言经典迭代算法之求解函数定积分(详解)
  5. Python验证码的生成
  6. python38使用_笨方法学Python 习题38:列表的操作
  7. idea 2020和2017下载
  8. python爬虫框架源码_python爬虫的基本框架
  9. Python+tkinter实现超时无键盘操作自动退出
  10. 代码统计工具有哪几种_DevOps:优秀代码分析工具的自我修养