CDI中的@ApplicationScoped和@Singleton范围有什么区别? [英] What is the difference between @ApplicationScoped and @Singleton scopes in CDI?

查看:73
本文介绍了CDI中的@ApplicationScoped和@Singleton范围有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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范围有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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