zoukankan      html  css  js  c++  java
  • Spring @Configuration注解

    1 该注解的用途

    这个注解表示这个类可以作为spring ioc容器bean的来源,其本质上它是对xml文件中创建bean的一种替换。有了这个注释,Spring framework就能在需要的时候构造出bean出来,然后完成bean的注入。

    2 一般使用方式

    package com.tutorialspoint;
    import org.springframework.context.annotation.*;
    @Configuration
    public class HelloWorldConfig {
       @Bean 
       public HelloWorld helloWorld(){
          return new HelloWorld();
       }
    }

    等价于
    <beans>
       <bean id="helloWorld" class="com.tutorialspoint.HelloWorld" />
    </beans>

    3 使用@Configuration创建单例

    @Bean默认就是单例的。

    4 关于@Configuration里面返回Bean的函数的名字

    这个名字可以任意取。

  • 相关阅读:
    Ubuntu 16 安装ElasticSearch
    二叉树
    归并排序
    快速排序
    Git、Github使用
    445. 两数相加 II
    141. 环形链表
    92. 反转链表 II
    19. 删除链表的倒数第N个节点
    2. 两数相加
  • 原文地址:https://www.cnblogs.com/hustdc/p/9541532.html
Copyright © 2011-2022 走看看