Java 在不同远程对象之间拆分远程EJB功能
我正在一个遗留系统上工作,其中有一个远程bean已经变得太大和单一,我希望将需要添加的新功能分开 我最初的想法是,不要将我的新方法添加到现有接口中,而是用我所有的东西创建一个新接口,并添加一个方法来返回实现我的接口的远程对象 我现在面临的问题是,当我调用返回对象的方法时,运行时会尝试序列化它,而不是发送存根 代码布局大致如下所示:Java 在不同远程对象之间拆分远程EJB功能,java,jakarta-ee,ejb-3.0,remoting,Java,Jakarta Ee,Ejb 3.0,Remoting,我正在一个遗留系统上工作,其中有一个远程bean已经变得太大和单一,我希望将需要添加的新功能分开 我最初的想法是,不要将我的新方法添加到现有接口中,而是用我所有的东西创建一个新接口,并添加一个方法来返回实现我的接口的远程对象 我现在面临的问题是,当我调用返回对象的方法时,运行时会尝试序列化它,而不是发送存根 代码布局大致如下所示: @Stateless public class OldBean implements OldRemoteInterface { //lots of the ol
@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"
我知道我一定错过了一些显而易见的东西-/ 你的方法有点混乱。创建新接口时,下一步应该是让旧bean实现新接口,如下所示:
public class OldBean implements OldRemoteInterface, NewRemoteInterface {
您的旧bean会变得更大,是的,但这是在不创建新bean或接触旧接口的情况下扩展旧bean功能的唯一方法
getNewStuff()返回的对象只是一个普通对象——它不是远程对象。这就是为什么会出现序列化错误,因为RMI正在尝试通过网络传输NewRemoteInterface实例。用@Remote注释它不会有任何作用(除非您实际使用bean上的接口,部署该bean,然后使用DI或上下文检索它)我明白了,当添加@Remote注释时,我希望在幕后执行更多的“黑魔法”。我也希望如此!)