是否有可能在一个EJB 3 bean来使用@WebService,@Stateless和@Singleton干脆? [英] Is it possible to use @WebService, @Stateless and @Singleton altogether in one EJB 3 bean?

查看:198
本文介绍了是否有可能在一个EJB 3 bean来使用@WebService,@Stateless和@Singleton干脆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用EJB 3和JBoss AS 6.0.0.Final。我有注释无状态会话bean @Stateless @WebService 。当我添加注释 @Singleton ,部署是错误的显示信息:

I'm using EJB 3 and JBoss AS 6.0.0.Final. I have a stateless session bean with the annotations @Stateless and @WebService. When I add the annotation @Singleton, the deployment is in error showing the message:

...名称= ServiceBean,服务= EJB3已经安装

...name=ServiceBean, service=ejb3 is already installed

我能做些什么来避免部署错误?

What can I do to avoid the deployment error?

推荐答案

您可以使用@WebService和@Stateless @WebService或与@辛格尔顿在同一个bean,这使得完美的,如果你要公开一个POJO既是一个Web感知服务和EJB。

You can use @WebService and @Stateless or @WebService and @Singleton in the same bean which makes perfectly sense if you want to expose a POJO as both a web service and EJB.

看不到太大的意义在同一个bean使用@Stateless和@Singleton。当您使用@Singleton,您将创建与所有的EJB功能的EJB(事务管理,安全等),正是因为有@Stateless。唯一的区别是容器如何管理EJB的生命周期:

Don't see much sense in using @Stateless and @Singleton in the same bean. When you use @Singleton, you are creating an EJB with all the EJB capabilities (transaction management, security, etc) exactly as with @Stateless. The only difference is how the container manages the EJB lifecycle:


  • @Stateless :在EJB实例的第一个请求后,立即创建和请求结束时,EJB组件被合并,并准备重用,如果还有其他​​请求到来但是,如果所有的实例池在当下正在使用另一个请求进入同一个bean,容器的创建相同的新实例,以满足新的要求。

  • @Singleton :第一个请求(默认情况下 - 看@Startup覆盖这种行为)后创建EJB实例进来,这将是在容器创建的唯一实例。如果另一个请求想要使用同一EJB,容器将从未创建它的一个新的实例 - pviously创建的实例$ P $将被使用。这就像用1 :)因素,如并发池大小@Stateless EJB使用这些的时候是很重要的,但是这可能是这个职位的范围。

  • @Stateless: the EJB instance is created immediately after the first request and when the request ends, the EJB is pooled and ready for reuse if another request comes in. However, if all the pooled instances are being used in the moment another request comes in for the same bean, the container creates a new instance of the same to serve that new request.
  • @Singleton: the EJB instance is created after the first request (by default - see @Startup to override this behavior) comes in and that will be the only instance created by the container. If another request wants to use the same EJB, the container will never create a new instance of it - the instance previously created will be used. It is like a @Stateless EJB with a pool size of 1 :) Aspects like concurrency are important when using these, but this is probably out of the scope of this post.

这篇关于是否有可能在一个EJB 3 bean来使用@WebService,@Stateless和@Singleton干脆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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