简体   繁体   English

将EJB3移植到EJB2

[英]Porting EJB3 to EJB2

This is a weird situation. 这是一个奇怪的情况。 Let me explain it as best as I can. 让我尽我所能地解释一下。

I have an interface Client which has methods which throw a Custom Exception. 我有一个Client接口,其中包含引发自定义异常的方法。 My EJB3 Remote extends this interface Client and was annotated @Remote . 我的EJB3 Remote扩展了此接口Client ,并@Remote注释。 My EJB3 Bean used to extend the Remote and was annotated @Stateless . 我的EJB3 Bean用于扩展Remote,并@Stateless注释。

Now comes the weirdness. 现在来了怪异。 Due to a very specific issue I cannot deploy any EJB3 jars on my app server. 由于一个非常具体的问题,我无法在我的应用服务器上部署任何EJB3 jar。 (The question is not how I resolve this deploy issue.) (问题不在于我如何解决此部署问题。)

Now I have to downgrade the code from EJB3 to EJB2. 现在,我必须将代码从EJB3降级到EJB2。 Since all the methods in my Remote Interface have to throw a RemoteException (EJB2 Spec) , I cannot extend from my Client Interface any more. 由于我的远程接口中的所有方法都必须抛出RemoteException (EJB2规范),因此我无法再从Client接口扩展。

The option that I am left with is creating a EJB2Wrapper, which can extend from the Client interface and in each method I call into the Remote Interface. 我剩下的选项是创建一个EJB2Wrapper,它可以从Client接口扩展,也可以在我调用的每个方法中扩展到Remote Interface。

This creates the ugly try catch block for each method, since I have to catch the RemoteException . 这为每个方法创建了丑陋的try catch块,因为我必须捕获RemoteException

Is there a better way to do this? 有一个更好的方法吗?

I would say that you would not be having such a big problem if the functionality in your beans started life as a POJO. 我会说,如果你的bean中的功能以POJO开头,你就不会遇到这么大的问题。 If you have that, you could simply deploy as EJB3, EJB2, servlet, web service, or anything else you wanted. 如果你有这个,你可以简单地部署为EJB3,EJB2,servlet,web服务或任何你想要的东西。

Perhaps the best solution is to extract the good from the EJB3 as a POJO and defer deployment choices until the end. 也许最好的解决方案是将EJB3中的产品作为POJO提取,并将部署选择推迟到最后。 I would prefer this solution to the EJB2Wrapper . EJB2Wrapper我更喜欢这种解决方案。 You already have to do some work; 您已经必须做一些工作。 best to invest in something that will have value even if you decide to go with REST web services instead of EJBs in the future. 即使您将来决定使用REST Web服务而不是EJB,最好还是投资具有价值的东西。

Answering my own question to close the loop. 回答我自己的问题来关闭循环。

There is no better way to do this as of now. 到目前为止,没有更好的方法可以做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM