美文网首页spring 相关
spring  注解--scope

spring  注解--scope

作者: aix91 | 来源:发表于2018-12-31 11:19 被阅读0次

scope用法

确定生成bean的使用范围:

  • singleton:每次生成的bean都一样,在加载IOC容器时,就已经注入到容器里了
  • prototype:每次都新生成bean
  • request:web每次请求中的bean一样
  • session:web每个session中的bean一样
public class MainConfig {
    @Scope(scopeName = "prototype")
    @Bean(name = {"person"})//容器中该bean的id默认是方法的名字
    public Person person1() {
        return new Person("test", 20);
    }
}

相关文章

  • spring注解之@Scope注解

    1.@Scope注解是什么 @Scope注解是springIoc容器中的一个作用域,在 Spring IoC 容器...

  • spring  注解--scope

    scope用法 确定生成bean的使用范围: singleton:每次生成的bean都一样,在加载IOC容器时,就...

  • 第二章 Spring常用配置

    第二章 Spring常用配置 2.1 Bean的Scope @Scope注解(1) singleton:一个Spr...

  • spring常用注解-@Scope

    Scope,也称作用域,在Soring Ioc容器指其创建的Bean对象对其他Bean对象的请求可见范围,在Spr...

  • Spring注解 @Scope学习

    scope的值:默认singleton单实例,prototype原型,request,sessionsinglet...

  • Spring 注解版

    文末有彩蛋 @Scope bean的生命周期 @Value 自动装配 @Profile AOP Spring注解驱动开发

  • 003Spring注解@Scope

    1、简介 @Scope指定bean的作用域。 2、基础类 3、@Scope 3.1、取值 3.2、默认值 Conf...

  • Spring注解(@Scope @Lazy @Condition

    @Scope注解指定注入容器的bean是单实例还是多实例的,默认情况下是单实例 ConfigurableBeanF...

  • Netty+spring

    如果Netty中hander是由spring的注解生成,那么需要在自定义Hander前加 @Scope("prot...

  • 第2章 Spring常用配置

    Bean中的Scope Scope是描述Spring如何创建Bean实例的。spring的Scope有以下几种:S...

网友评论

    本文标题:spring  注解--scope

    本文链接:https://www.haomeiwen.com/subject/rgjilqtx.html