EJB例子:既支持远程又支持本地调用

例子如下:
 
 
定义远程接口 Operation.java

package com.elifefly.ejb3; public interface Operation { public int Add(int a, int b); }

定义本地接口 LocalOperation.java, 本地接口具有远程接口的所有方法, 另外有自己的方法getResult()

package com.elifefly.ejb3; public interface LocalOperation extends Operation { public int getResult(); }

 
实现本地接口和远程接口的会话Bean: OperationBean.java

注意

@Stateless 
@Remote ({Operation.class}) 
@Local ({LocalOperation.class})

这三个同时存在

package com.elifefly.ejb3.impl; import javax.ejb.Local; import javax.ejb.Remote; import javax.ejb.Stateless; import com.foshanshop.ejb3.LocalOperation; import com.foshanshop.ejb3.Operation; @Stateless @Remote ({Operation.class}) @Local ({LocalOperation.class}) public class OperationBean implements Operation, LocalOperation { private int total = 0; private int addresult = 0; public int Add(int a, int b) { addresult = a b; return addresult; } public int getResult() { total = addresult; return total; } }   

 

 

 

 

 

 

你可能感兴趣的:(EJB例子:既支持远程又支持本地调用)