我正在研究一個Java Enterprise應用程序,它具有與EAR捆綁在一起的EJB層和WEB層。我面臨的問題是,我的EJB層中有一些實體,當我嘗試通過JNDI在我的WEB層獲取EAO時,我得到了NameNotFoundException。NameNotFoundException Java企業應用程序
我耳邊的名字是:StudentManagement
我EJB層:StudentManagementEJB
我的Web層:StudentManagementWEB
應用服務器:JBOSS-4.2
我的實體類:
@Entity
@Table(name="student")
public class Student implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="student_id")
private int studentId;
@Column(name="sudent_name")
private String studentName;
@Column(name="student_class")
private String studentClass;
public int getStudentId() {
return studentId;
}
public void setStudentId(int studentId) {
this.studentId = studentId;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getStudentClass() {
return studentClass;
}
public void setStudentClass(String studentClass) {
this.studentClass = studentClass;
}
}
我的遙遠的Inteface:
@Remote
public interface StudentEAO {
public void save(Student student);
}
我的接口實現:
@Stateless
public class StudentEAOImpl implements StudentEAO {
@PersistenceContext
private EntityManager entityManager;
/* (non-Javadoc)
* @see com.learn.interfce.StudentEAO#save(com.learn.entity.Student)
*/
@Override
public void save(Student student) {
// TODO Auto-generated method stub
try{
entityManager.persist(student);
}
catch(Exception e){
e.printStackTrace();
}
}
}
並在我的servlet,我試圖讓StudentEAOImpl對象爲
try {
StudentEAO studentEao = (StudentEAO) new InitialContext().lookup("StudentManagement/StudentEAOImpl/remote");
studentEao.save(student);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
堆棧跟蹤錯誤的:
01:15:45,539 INFO [STDOUT] Hello World from StudentActionServlet.
01:15:45,543 ERROR [STDERR] javax.naming.NameNotFoundException: StudentManagement not bound
01:15:45,543 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
01:15:45,543 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
01:15:45,543 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
01:15:45,543 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
01:15:45,543 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:628)
01:15:45,543 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:590)
01:15:45,543 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:392)
01:15:45,543 ERROR [STDERR] at com.learn.servlets.StudentActionServlet.doGet(StudentActionServlet.java:46)
我沒有得到什麼,我在這裏失蹤。在這方面請幫助我。
謝謝!