我正在试图在同一个Glassfish中使用本地EJB,但不同的耳朵.但Glassfish无法找到本地EJB或无法使用
我看了这个:
根据JavaEE教程,@ Local bean的客户端必须在与其访问的企业bean相同的JVM中运行.
在第一只耳朵里,
我在jar里面有本地接口
@Local public interface MyLocalBean { int getNumber(int num3); }
在另一个jar中,我有实现
@Stateless @LocalBean public class MyLocalBeanImpl implements MyLocalBean,Serializable{ public MyLocalBeanImpl() {} public int getNumber(int num3){......
在第二只耳朵里,
在同一个Glassfish中
我在jar里面有本地接口
@Local public interface MyLocalBean { int getNumber(int num3); }
在另一个罐子里,我有消费者
@Stateless @LocalBean public class BeanConsumer{ @EJB(name="MyLocalBeanImpl") private MyLocalBean beanlocal;
使用@EJB和(name =“MyLocalBeanImpl”)参数时,错误是:
Cannot resolve reference Local ejb-ref name=MyLocalBeanImpl,Local 3.x interface =my.package.MyLocalBean,ejb-link=null,lookup=,mappedName=,jndi-name=,refType=Session|#]
使用@EJB和(name =“my.package.MyLocalBeanImpl”)参数,错误是:
Cannot resolve reference Local ejb-ref name=my.package.MyLocalBeanImpl,Local 3.x interface =my.package.MyLocalBean,refType=Session|#]***
我也尝试使用mappedName
@Stateless(name="MyLocalBeanImpl",mappedName ="MyLocalBeanImpl") public class MyLocalBeanImpl implements MyLocalBean{ @EJB(name="MyLocalBeanImpl",mappedName ="MyLocalBeanImpl") private MyLocalBean beanlocal;
但错误仍然存在
Cannot resolve reference Local ejb-ref name=MyLocalBeanImpl,mappedName=MyLocalBeanImpl,refType=Session
GlassFish与JNDI一样工作
java:global[/<app-name>]/<module-name>/<bean-name>
我将注释@LocalBean添加到bean MyLocalBeanImpl中
@Stateless @LocalBean public class MyLocalBeanImpl implements MyLocalBean{ public MyLocalBeanImpl() {} public int getNumber(int num3){......
当我部署Glassfish说jndi是两个
Portable JNDI names for EJB OtroBean java:global/myfirstear/myejbs/MyLocalBeanImpl!my.package.MyLocalBeanImpl and java:global/myfirstear/myejbs/MyLocalBeanImpl!my.package.MyLocalBean
我正在尝试
@EJB(lookup="java:global/myfirstear/myejbs/MyLocalBeanImpl!my.package.MyLocalBeanImpl")
似乎Glassfish找到了Local Bean,但是…… Glassfish在运行这样的东西时遇到了问题
javax.naming.NamingException javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB at com.sun.ejb.containers.StatelessSessionContainer ._getContext(StatelessSessionContainer.java:454) ..... Caused by: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB .... Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Local ejb-ref name=my.package.BeanConsumer/beanlocal,lookup=java:global/myfirstear/myejbs/MyLocalBeanImpl!my.package.MyLocalBeanImpl,refType=Session into class my.package.BeanConsumer: Can not set my.package.MyLocalBean field my.package.BeanConsumer.beanlocal to my.package.beans.__EJB31_Generated__MyLocalBeanImpl__Intf____Bean__
并尝试
@EJB(lookup="java:global/myfirstear/myejbs/MyLocalBeanImpl")
我明白了:
throws javax.naming.NamingException javax.ejb.EJBException: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Local ejb-ref name=my.package.BeanConsumer/beanlocal,Local 3.x interface =my.package.MyLocalBean,lookup=java:global/myfirstear/myejbs/MyLocalBeanImpl,refType=Session into class my.package.BeanConsumer: Lookup Failed for 'java:comp/env/my.package.BeanConsumer/beanlocal' in SerialContext [myEnv={java.naming.factory.initial= com.sun.enterprise.naming.impl.SerialInitContextFactory,java.naming.factory.state= com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,java.naming.factory.url.pkgs= com.sun.enterprise.naming}