我从数据库创建了实体类,然后我从实体类创建了会话bean
并且当我试图测试我的数据到达实体类时,我已经在会话bean类上创建了一个junit测试,但我查找失败“根异常是javax.naming.NameNotFoundException
:EmpTableFacade!Beans.EmpTableFacade找不到,即使我使用EJB注入
然后我尝试通过创建使用会话bean的类来手动测试我的代码,但这里有相同的异常。
我认为部署员工的错误但我不知道我在哪里做错了 这是会话bean界面。
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Beans;
import java.util.List;
import javax.ejb.Local;
/**
*
* @author HADDAD
*/
@Local
public interface EmpTableFacadeLocal {
void create(EmpTable empTable);
void edit(EmpTable empTable);
void remove(EmpTable empTable);
EmpTable find(Object id);
List<EmpTable> findAll();
List<EmpTable> findRange(int[] range);
int count();
}
and this is the test class
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Controller;
import Beans.EmpTable;
import Beans.EmpTableFacade;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
*
* @author HADDAD
*/
public class Functionality {
List<EmpTable> l;
Context c=null;
{
try {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
// glassfish default port value will be 3700,
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
//props.load(new FileInputStream("jndi.properties"));
c = new InitialContext(props);
} catch (NamingException ex) {
Logger.getLogger(Functionality.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void retrive() throws NamingException
{
EmpTableFacade empTableFacade=(EmpTableFacade)
c.lookup("java:global/employee/employee-ejb/EmpTableFacade!Beans.EmpTableFacade");
l= empTableFacade.findAll();
System.out.println(l.get(0).getName().toString());
}
public static void main(String[] args) throws NamingException
{
Functionality f=new Functionality();
f.retrive();
}
}
这是例外
Exception in thread "main" javax.naming.NamingException: Lookup failed for 'java:global/employee/employee-ejb/EmpTableFacade!Beans.EmpTableFacade' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NameNotFoundException: EmpTableFacade!Beans.EmpTableFacade not found]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at Controller.Functionality.retrive(Functionality.java:45)
at Controller.Functionality.main(Functionality.java:52)