我正在尝试实现EJB模块,但是当客户端应用程序尝试检索接口对象时,我收到错误。客户端应用程序具有与EJB模块相同的接口文件,但在其各自的本地程序包中。我认为错误发生在服务器端。我从this tutorial复制了这个例子,但是使用了glassfish服务器;本教程中解释的简单EJB工作正常,但是当我尝试应用相同的理论来实现更复杂的EJB时,它不起作用。当然我做错了,但没有太多关于这个错误的信息,我真的迷路了。
这是来自客户端应用程序的错误
javax.naming.NamingException: Lookup failed for 'java:global/ManagementUtils/UsuarioService' 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.NamingException: ejb ref resolution error for remote business interfacecom.management.persistence.interfaces.service.UsuarioServiceRemote [Root exception is java.lang.ClassNotFoundException: com.management.persistence.interfaces.service.UsuarioServiceRemote]]
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:417)
at com.management.test.MainClass.main(MainClass.java:12)
Caused by: javax.naming.NamingException: ejb ref resolution error for remote business interfacecom.management.persistence.interfaces.service.UsuarioServiceRemote [Root exception is java.lang.ClassNotFoundException: com.management.persistence.interfaces.service.UsuarioServiceRemote]
at com.sun.ejb.EJBUtils.lookupRemote30BusinessObject(EJBUtils.java:433)
at com.sun.ejb.containers.RemoteBusinessObjectFactory.getObjectInstance(RemoteBusinessObjectFactory.java:75)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance(SerialContext.java:527)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:487)
... 3 more
Caused by: java.lang.ClassNotFoundException: com.management.persistence.interfaces.service.UsuarioServiceRemote
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.sun.ejb.EJBUtils.getBusinessIntfClassLoader(EJBUtils.java:685)
at com.sun.ejb.EJBUtils.loadGeneratedRemoteBusinessClasses(EJBUtils.java:462)
at com.sun.ejb.EJBUtils.lookupRemote30BusinessObject(EJBUtils.java:413)
... 7 more
这是EJB模块中的EJB UsuarioService
:
package com.management.persistence.service;
import com.management.persistence.interfaces.service.UsuarioServiceRemote;
import com.management.persistence.dao.UsuarioDao;
import com.management.persistence.model.Usuario;
import com.management.persistence.facades.ServiceFacade;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import org.springframework.beans.factory.annotation.Autowired;
@Stateless
@Remote(UsuarioServiceRemote.class)
public class UsuarioService extends ServiceFacade implements UsuarioServiceRemote {
@Autowired
private UsuarioDao usuariosDao;
public UsuarioService() {
}
public UsuarioService(UsuarioDao usuariosDao) {
super(usuariosDao);
this.usuariosDao = usuariosDao;
}
@Override
public UsuarioDao getUsuariosDao() {
return usuariosDao;
}
@Override
public Usuario findByUsuarioAndContrasena(String login, String contrasena) {
validateSession();
Usuario usuario = usuariosDao.findByUsuarioAndContrasena(login, contrasena);
closeCurrentSession();
return usuario;
}
}
这是EJB模块中的接口UsuarioServiceRemote
:
package com.management.persistence.interfaces.service;
import com.management.persistence.interfaces.ServiceFacadeRemote;
import com.management.persistence.interfaces.dao.UsuarioDaoRemote;
import com.management.persistence.model.Usuario;
public interface UsuarioServiceRemote extends ServiceFacadeRemote {
public UsuarioDaoRemote getUsuariosDao();
public Usuario findByUsuarioAndContrasena(String login, String contrasena);
}
答案 0 :(得分:0)
谢谢@SteveC是的,实际上,我的错误是包名,它在客户端应用程序中与服务器不同,所以在客户端应用程序中我重命名了业务接口的包,也是相同的实体课,之后一切运作良好。