问题描述
在CDI中有@ApplicationScoped
和(javax.inject
)@Singleton
伪作用域.它们之间有什么区别?除了@ApplicationScoped
被代理而@Singleton
不被代理的事实.
In CDI there is the @ApplicationScoped
and the (javax.inject
) @Singleton
pseudo-scope. What is the difference between them? Besides the fact that @ApplicationScoped
is proxied, and @Singleton
is not.
我可以只将我的@Singleton
bean更改为@ApplicationScoped
吗? @ApplicationScoped
bean可以有两个(或更多)实例吗?
Can I just change my @Singleton
bean to @ApplicationScoped
? Can @ApplicationScoped
bean have two (or more) instances?
推荐答案
@Singleton
不属于CDI规范.它是EJB和javax.inject
(JSR-330)的一部分.规范中没有提到它的行为,因此您只能依靠Weld文档中写的内容.
@Singleton
is not part of the CDI specification. It is part of EJB and javax.inject
(JSR-330). It is not mentioned in the spec what is its behaviour, so you can only rely on what's written in the Weld documentation.
这篇关于CDI中的@ApplicationScoped和@Singleton范围有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!