gpt4 book ai didi

spring - 在 Spring 范围 ="singleton"和单例 ="true"之间的确切区别是什么

转载 作者:行者123 更新时间:2023-12-04 02:09:38 24 4
gpt4 key购买 nike

在一次采访中我遇到过这个问题。在 spring 配置文件中,如果我们给 scope="singleton"和 singleton="true"会发生什么。

最佳答案

嗯,在 Spring 1.x 中只有两个作用域,prototypesingleton,所以只有 singleton=true 或者一个 singleton=false。引用 DTD:

Bean instances can be "singletons" (shared instances) or "prototypes" (independent instances). Further scopes are supposed to be built on top of the core BeanFactory infrastructure and are therefore not part of it.

( Source )

但是,这不允许他们引入其他作用域,因此他们在 Spring 2 中将 DTD 更改为 scope="singleton"scope="prototype" .这使他们也可以引入其他范围,例如 scope="session"scope="request"。您可以在 DTD of Spring 2 中验证这一点及以后。


因此,要回答您的问题,通常它们应该相同,但在不同版本的 Spring 中。

关于spring - 在 Spring 范围 ="singleton"和单例 ="true"之间的确切区别是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39911292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com