【问题标题】:Splitting remote EJB functionality between different remote objects在不同的远程对象之间拆分远程 EJB 功能
【发布时间】:2011-03-01 10:02:13
【问题描述】:

我正在开发一个遗留系统,其中有一个远程 bean 变得太大且过于单一,我想将需要添加的新功能分开。

我最初的想法是,与其将我的新方法添加到现有接口,不如使用我的所有东西创建一个新接口,并添加一个返回实现我的接口的远程对象的方法。

我现在面临的问题是,当我调用返回对象的方法时,运行时会尝试序列化它而不是发送存根。

代码布局大致是这样的:

@Stateless
public class OldBean implements OldRemoteInterface {
   //lots of the old unrelated methods here

   public MyNewStuff getMyNewStuff() {
      return new MyNewStuff();
   }
}

@Remote
public interface OldRemoteInterface {
   //lots of the old unrelated methods declared here

   MyNewStuff getMyNewStuff();
}

public class MyNewStuff implements NewRemoteInterface {
   //methods implemented here
}

@Remote
public interface NewRemoteInterface {
   //new methods declared here
}

我得到的例外是:

"IOP00810267: (MARSHAL) An instance of class MyNewStuff could not be marshalled:
the class is not an instance of java.io.Serializable"

我尝试过“旧方式”,扩展java.rmi.Remote 接口而不是使用ejb @Remote 注释,我得到的例外是:

"IOP00511403: (INV_OBJREF) Class MyNewStuff not exported, or else is actually 
a JRMP stub"

我知道我一定遗漏了一些应该很明显的东西...:-/

【问题讨论】:

    标签: java jakarta-ee ejb-3.0 remoting


    【解决方案1】:

    您的方法有点令人困惑。当您创建新接口时,下一步应该是让旧 bean 实现新接口,如下所示:

    public class OldBean implements OldRemoteInterface, NewRemoteInterface {
    

    您的旧 bean 会变大,是的,但这是您无需创建新 bean 或接触旧界面即可扩展旧 bean 功能的唯一方法。

    getNewStuff() 返回的对象只是一个普通对象——它不是远程对象。这就是您收到序列化错误的原因,因为 RMI 正在尝试通过网络传输您的 NewRemoteInterface 实例。用 @Remote 注释它不会做任何事情(直到你实际使用 bean 上的接口,部署该 bean,然后使用 DI 或上下文检索它)

    【讨论】:

    • 我明白了,当添加 @Remote 注释时,我期待更多的“黑魔法”在幕后执行。
    • 我也希望是这样! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-19
    • 2014-08-22
    • 1970-01-01
    相关资源
    最近更新 更多