Java Tutorial/EJB3/Injection
Версия от 17:44, 31 мая 2010; (обсуждение)
Содержание
EJB Field Injection
File: AnotherEJBLocal.java
import javax.ejb.Local;
@Local
public interface AnotherEJBLocal {
public void doAnother();
}
Inject EJB With EJB Annotation
File: AnotherEJBLocal.java
import javax.ejb.Local;
@Local
public interface AnotherEJBLocal {
public void doAnother();
}
Inject Session Context
File: Employee.java
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.PostRemove;
@Entity
public class Employee implements java.io.Serializable {
private int id;
private String firstName;
private String lastName;
@Id
@GeneratedValue
public int getId() {
return id;
}
@PostRemove
public void postRemove()
{
System.out.println("@PostRemove");
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String first) {
this.firstName = first;
}
public String getLastName() {
return lastName;
}
public void setLastName(String last) {
this.lastName = last;
}
}
Setter Injection
File: AnotherEJBLocal.java
import javax.ejb.Local;
@Local
public interface AnotherEJBLocal {
public void doAnother();
}