1.5.4.4. Application Scope(应用作用域)

 Spring Framework Documentation (5.3.10)

Core

IoC Container, Events, Resources, i18n, Validation, Data Binding, Type Conversion, SpEL, AOP.

   Core Technologies

1. The IoC Container

1.1. Introduction to the Spring IoC Container and Beans(Spring IoC容器和bean简介)

1.2. Container Overview (容器概览)

1.3. Bean Overview (Bean概览)

1.4. Dependencies(依赖)

1.5. Bean Scopes(Bean作用域)

1.5.1. The Singleton Scope (单例作用域)

1.5.2. The Prototype Scope(Prototype作用域)

1.5.3. Singleton Beans with Prototype-bean Dependencies(单例和原型Bean的依赖)

1.5.4. Request, Session, Application, and WebSocket Scopes

1.5.4.1. Initial Web Configuration (初始化Web配置)

1.5.4.2. Request scope(请求作用域)

1.5.4.3. Session Scope(会话作用域)

1.5.4.4. Application Scope(应用作用域)

1.5.4.5. Scoped Beans as Dependencies (具有作用域的bean作为依赖项)

1.5.4.5.1 Choosing the Type of Proxy to Create(选择待创建代理的类型)

1.5.5. Custom Scopes (自定义作用域)

1.5.5.1. Creating a Custom Scope(创建自定义作用域)

1.5.5.2. Using a Custom Scope (使用自定义作用域)


下载此文档精编完整版

 No.内容下载地址文档内容目录
1中英双语精编版 第一部分PDF下载内容目录
2中英双语精编版 第二部分PDF下载内容目录
3中文精编版 第一部分PDF下载内容目录
4中文精编版 第二部分PDF下载内容目录

更多章节内容,请点击查看:  Core Technologies


1.5.4.4. Application Scope(应用作用域)

Consider the following XML configuration for a bean definition:

考虑以下bean定义的XML配置:

<bean id="appPreferences" class="com.something.AppPreferences" scope="application"/>

The Spring container creates a new instance of the AppPreferences bean by using the appPreferences bean definition once for the entire web application. That is, the appPreferences bean is scoped at the ServletContext level and stored as a regular ServletContext attribute. This is somewhat similar to a Spring singleton bean but differs in two important ways: It is a singleton per ServletContext, not per Spring 'ApplicationContext' (for which there may be several in any given web application), and it is actually exposed and therefore visible as a ServletContext attribute.

Spring容器通过为整个web应用程序使用AppPreferences bean定义一次来创建AppPreferences bean的一个新实例。也就是说,AppPreferences bean的作用域限定在ServletContext 级别,并作为常规ServletContext 属性存储。这有点类似于Spring单例beanSpring singleton bean),但在两个重要方面有所不同:它是每个ServletContext 的单例,而不是每个SpringApplicationContext”(在任何给定的web应用程序中可能有多个),并且它实际上是公开的,因此作为ServletContext 属性可见。

When using annotation-driven components or Java configuration, you can use the @ApplicationScope annotation to assign a component to the application scope. The following example shows how to do so:

使用注解驱动组件或Java配置(annotation-driven components or Java configuration)时,可以使用@ApplicationScope注解将组件分配为应用作用域(application scope)。以下示例展示了如何执行此操作:

Java

@ApplicationScope
@Component
public class AppPreferences {
    // ...
}

Kotlin

@ApplicationScope
@Component
class AppPreferences {
    // ...
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

月满闲庭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值