Spring Request和Prototype范围? [英] Spring Request and Prototype Scope?

查看:173
本文介绍了Spring Request和Prototype范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是Spring中原型和请求范围的定义.

Below are the definitions of prototype and request scope in Spring.

原型 将单个bean定义的作用域限定为任意数量的对象实例.

prototype Scopes a single bean definition to any number of object instances.

要求 将单个bean定义的范围限定为单个HTTP请求的生命周期;那就是每个HTTP请求都会有自己的请求 在单个bean定义的后面创建的bean实例.仅在可感知网络的Spring ApplicationContext上下文中有效.

request Scopes a single bean definition to the lifecycle of a single HTTP request; that is each and every HTTP request will have its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext.

据我了解,在原型作用域的情况下,核心容器将维护一些池.它将为该池中的bean实例提供服务. 在请求范围的情况下,将为每个http请求提供新的bean.如果理解上有些差异,请纠正我?

As per my understanding In case of prototype scope , some pool will be maintained by core container. It will serve the bean instance from that pool. In case of request scope, new bean will be served for each http request. Please correct me if there is some dicrepency in understanding?

如果以上语句为真,则如果bean处于某种状态,则不应将范围定义为原型,而应将其定义为 就像要求的一样.正确吗?

If above statements are true, then if bean is holding some state then the scope should not be defined as prototype rather it should be defined as request. Correct?

推荐答案

您离开了.原型在docs

You are off. Prototype is described in the docs here as

非单例,原型范围 Bean部署导致 每创建一个新的bean实例 为那个特定的bean安排一个请求 制成."

"The non-singleton, prototype scope of bean deployment results in the creation of a new bean instance every time a request for that specific bean is made."

您对请求范围的Bean的描述是准确的.

Your description of request scoped beans is accurate.

可能是电线相对于原型与单例交叉了.

Probably just got the wires crossed vis-a-vis prototype vs singleton.

这篇关于Spring Request和Prototype范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆