考虑以下有状态EJB(3.x):
第一个远程接口:
@Remote
public interface Interface1
{
public void setValue(int v);
}
第二个远程接口:
@Remote
public interface Interface2
{
public int getValue();
}
接口的实现:
@Stateful
public class TheEJB implements Interface1, Interface2
{
int value = 0;
public void setValue(int v) {value = v;}
public int getValue() {return value;}
}
如果我在客户端执行以下操作:
Interface1 interface1 = (Interface1)initialContext.lookup("***JNDI for Interface1***");
Interface2 interface2 = (Interface2)initialContext.lookup("***JNDI for Interface2***");
interface1.setValue(1);
System.out.println(interface2.getValue());
控制台的输出将为0,因为interface2
未指向与interface1
相同的会话bean实例。
所以,我的问题是,是否有可能在创建interface2
时将其指向与interface1
相同的bean实例(从而获得输出1)?
我确实意识到这可以通过将两个方法放在一个接口中来实现,但是让我们说两个接口因为某种原因而使用两个接口。
非常感谢。