EJB3.0 draft学习笔记(1)

来源:互联网 发布:软件教育现代化官网 编辑:程序博客网 时间:2024/04/28 12:41

EJB3.0 draft学习笔记(1)

今天开始学习EJB3.0 draft,大家可能都知道了,一个有状态会话bean长得象这样:
@Stateful public class CartBean implements ShoppingCart {
private float total;
private Vector productCodes;
public int someShoppingMethod(){...};
...
ejbRemove() {...};
}
其它类型的我就不用说了吧...

规范中对entity bean的接口没有做具体规定,但sesseion bean 和MDB肯定是有个接口的。
一个bean类可以实现一个或多个接口:
/*
* The bean class implements the Calculator business interface:
*/
@Stateless public class CalculatorBean implements Calculator {
public float add (int a, int b) {
return a + b;
}
public float subtract (int a, int b) {
return a - b;
}
}
public interface Calculator {
public float add (int a, int b);
public float subtract (int a, int b);
}
如果没有实现接口,则会自动为它产生接口:
/*
* This class definition causes the Calculator
* interface to be generated as a local business interface.
* This interface will have the methods add and subtract.
*/
@Stateless public class CalculatorBean {
public float add (int a, int b) {
return a + b;
}
Enterprise Bean Class and Business Interface Enterprise JavaBeans 3.0, Early Draft

Exceptions
Sun Microsystems Inc.
public float subtract (int a, int b) {
return a - b;
}
}
产生的接口是什么名称呢?肯定是要规定的罗。根据bean类的名称来决定接口的名称。


?




原创粉丝点击