使用本地EJB,在同一个容器中但不同耳朵
我试图在同一个Glassfish中使用本地EJB,但使用不同的耳朵。 但Glassfish无法找到本地EJB或无法使用
我读到: 根据JavaEE教程,@Local bean的客户端“必须与它访问的企业bean在同一个JVM中运行。”
在第一个耳朵里 ,我有一个罐子里的本地接口
@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,ejb-link=null,
lookup=,mappedName=,jndi-name=,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,
Local 3.x interface =my.package.MyLocalBean,ejb-link=null,
lookup=,mappedName=MyLocalBeanImpl,jndi-name=,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,
Local 3.x interface =my.package.MyLocalBean,ejb-link=null,
lookup=java:global/myfirstear/myejbs/MyLocalBeanImpl!my.package.MyLocalBeanImpl,
mappedName=,jndi-name=,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,
ejb-link=null,
lookup=java:global/myfirstear/myejbs/MyLocalBeanImpl,
mappedName=,jndi-name=,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}
可以将本地EJB注入到同一个JVM中的另一个EJB中,但不同的耳朵。
问题是你不能再依赖于bean的名字,因为你需要告诉consumer bean完整的JNDI名称。 您可以在部署期间在服务器日志中找到该名称; 当bean绑定到JNDI目录时,服务器在日志中显示它。
链接地址: http://www.djcxy.com/p/10075.html上一篇: Consuming local EJB, in the same Container but different ears