EJB主要有三种类型:会话Bean,实体Bean和消息驱动Bean。会话Bean完成一个清晰的解耦的任务,会话bean用于执行特定的业务逻辑操作的目的,分为两种类型:有状态(stateful)和无状态(stateless)。实体Bean用于持久化,通过JPA的EntityManager接口以提供持久化服务的方式管理实体。。消息驱动Bean用于通常用于健壮的系统的集成或者异步处理
会话Bean例子
package com.landingbj.com;
import javax.ejb.Stateless;
@Stateless(name="testSessionEJB")
public class testSessionEJBBean implements testSessionEJB{
int num = 0;
@Override
public String incrementValue() {
num++;
return "num incremented by 1";
}
public static void main(String[] args) {
testSessionEJBBean tsBean = new testSessionEJBBean();
tsBean.incrementValue();
System.out.println(tsBean.num);
}
}
实体Bean
package com.landingbj.com;
import java.nio.Buffer;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="STUDENTS")
public class Student implements java.io.Serializable{
private int stuId;
private String name;
private String age;
@Id
@Column(name="STUID",primaryKey=true)
public int getStuId() {
return stuId;
}
public void setStuId(int stuId) {
this.stuId = stuId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String toString(){
StringBuffer bf = new StringBuffer();
bf.append("stuId").append("name").append("age");
return bf.toString();
}
}
以上仅仅是对EJB的初步了解,在学习好weblogic并且安装其相应的运行环境后,再学习将其部署到weblogic上!