- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在一次采访中我遇到过这个问题。在 spring 配置文件中,如果我们给 scope="singleton"和 singleton="true"会发生什么。
最佳答案
嗯,在 Spring 1.x 中只有两个作用域,prototype 和 singleton,所以只有 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/
是否有一个意思是“不是单例”的名字? 最佳答案 CaSTLe Windsor 使用术语“ transient ”来描述所有非单例对象。 不过,我个人更喜欢“非单例”一词。 关于singleton -
我有很多(抽象)工厂,它们通常被实现为单例。 通常是为了方便,不必让他们通过那些真正与使用或了解这些工厂无关的层。 大多数时候我只需要在启动时决定其余代码程序的工厂实现,也许通过一些配置 它看起来例如
我有几个关卡都使用相同的音效。我没有在每个级别都使用相同的代码,而是将所有声音合并到一个单例类中。但是,当我从其他类运行该方法时,将其置于单例中不会播放任何声音。我没有错误或警告。 当我在每个类中使用
我应该使用 EJB-@Singleton (javax.ejb.Singleton) 进行统计或监控,还是将统计信息缓存在公共(public) @SessionScoped-Bean 中会更好?为了澄
我有这个单例类: public class Utente { private static readonly Lazy lazy = new Lazy(() => new Utente
我的 iOS 应用程序对 Web 服务做了很多不同的请求。每个请求都是对 ConnectionManager 对象的方法的调用。当响应从 Web 服务到达时,将调用委托(delegate)的方法来通知
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: cracking singleton with other ways 任何人都可以告诉我 Singleton不能用作
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: cracking singleton with other ways 任何人都可以告诉我 Singleton不能用作
做用 @Singleton 注释的类必须遵循 Singleton design pattern ? 我的猜测是他们没有:没有必要有私有(private)构造函数和 static .instance()
我想提供 Java 中可用的内置单例类列表以及使它们成为单例的原因。 对于 E.G. java.lang.Runtime 原因:因为整个 Java 应用程序只能有一个运行时环境。 java.awt.T
我有一个 Python 3 类,它目前是使用 @singleton 装饰器定义的单例,但有时它需要不是是单例。 问题:是否可以在实例化类的对象时传递一个参数,由该参数决定该类是单例还是非单例? 我正试
我正在使用 get_it 包,你有两个选项来注册单例,懒惰和我猜是“常规”(分别是 GetIt.instance.registerLazySingleton 和 GetIt.instance.regi
单例模式在 Spring 容器级别维护实例,而单例设计模式在类加载器级别维护实例。 还有其他区别吗? 其次,我仍然认为上述理由不成立。事实上,一个应用程序上下文/容器仅加载在一个类加载器中。因此从技术
这个问题在这里已经有了答案: What is an undefined reference/unresolved external symbol error and how do I fix it?
在 Guice 中,有什么区别: // Inside your AbstractModule subclass: @Override public void configure() { bin
我使用 pthread TLS 实现了一种“线程本地单例”,我想知道在这种情况下我如何(以及何时)可以删除 pthread_key_t,因为就像现在一样,TLS key 使用的内存永远不会空闲' d。
如何从 @Singleton 组件返回非单例对象? 例如我有: ApplicationComponent.kt @Singleton @Component(modules = [Application
我正在学习 Dagger 2,我注意到在某些示例中,模块方法中有一个 @Singleton,而组件方法中有其他 @Singleton?模块方法和组件方法上的 @Singleton 批注有什么区别,究竟
我的代码中需要一个单例。我读了 Jon Skeet 的 page在单例上并根据他的推荐选择了这个模型(#4): public sealed class Singleton { private
我正在尝试使用 label2rgb 生成 RGB 标签切片并使用它来更新 RGB 体积,如下所示: labelRGB_slice=label2rgb(handles.label(:,:,han
我是一名优秀的程序员,十分优秀!