消耗本地EJB,在同一容器但不同的耳朵 [英] Consuming local EJB, in the same Container but different ears
问题描述
我读过这个:
根据JavaEE教程,客户端@Local bean必须在与其访问的企业bean相同的JVM中运行。
在第一个耳朵中,
我有一个jar中的本地界面
@Local
public interface MyLocalBean {
int getNumber(int num3);
}
在另一个jar中,我有实现
@Stateless
@LocalBean
public class MyLocalBeanImpl实现MyLocalBean,Serializable {
public MyLocalBeanImpl(){}
public int getNumber(int num3){...
在第二个耳朵,
在同一个Glassfish中
我有一个jar中的本地界面
@Local
public interface MyLocalBean {
int getNumber(int num3);
}
在另一个jar中,我有消费者
@Stateless
@LocalBean
public class BeanConsumer {
@EJB(name =MyLocalBeanImpl)
private MyLocalBean beanlocal;
与@EJB和(name =MyLocalBeanImpl)参数的错误是:
无法解析参考本地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)参数的错误是:
无法解析引用本地ejb-ref name = my.package.MyLocalBeanImpl,
本地3.x接口= my.package.MyLocalBean,ejb-link = null,
lookup =,mappedName =,jndi-name =,refType =会话|#] ***
我也尝试使用mappedName
$
public class MyLocalBeanImpl实现MyLocalBean {
@EJB (name =MyLocalBeanImpl,mappedName =MyLocalBeanImpl)
private MyLocalBean beanlocal;
但错误仍然存在
无法解析参考本地ejb-ref name = MyLocalBeanImpl,
本地3.x接口= 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实现MyLocalBean {
public MyLocalBeanImpl(){}
public int getNumber #$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
p>
EJB的便携式JNDI名称OtroBean
java:global / myfirstear / myejbs / MyLocalBeanImpl!my.package.MyLocalBeanImpl
和
java:global / myfirstear / myejbs / MyLocalBeanImpl!my.package.MyLocalBean
我正在尝试使用
@EJB(lookup =java:global / myfirstear / myejbs / MyLocalBeanImpl!my.package.MyLocalBeanImpl )
似乎Glassfish发现了本地Bean,但... Glassfish有问题,像这样
javax.naming.NamingException
javax.ejb.EJB异常:javax.ejb.CreateException:无法在
创建无状态EJB
com.sun.ejb.containers.StatelessSessionContainer
._getContext(StatelessSessionContainer.java:454)
.. ...
导致:javax.ejb.EJBException:
javax.ejb.CreateException:无法创建无状态EJB
....
导致:com.sun。 enterprise.container.common.spi.util.InjectionException:
尝试注入的异常本地ejb-ref name = my.package.BeanConsumer / beanlocal,
本地3.x接口= 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 :
无法将my.package.MyLocalBean字段my.package.BeanConsumer.beanlocal
设置为my.package.beans .__ EJB31_Generated__MyLocalBeanImpl__Intf____Bean__
并尝试使用
@EJB(lookup =java:global / myfirs我/ b
我得到:
throws javax.naming.NamingException
javax.ejb.EJBException:javax.ejb.EJBException:javax.ejb.CreateException:无法创建无状态EJB
导致:com.sun.enterprise.container.common.spi.util.InjectionException:
异常尝试注入本地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的名称,因为您需要告诉消费者bean完整的JNDI名称。您可以在部署期间在服务器日志中找到此名称;该bean绑定到服务器在日志中显示的JNDI目录。
I'm triying to consume a Local EJB in the same Glassfish, but different ears. But Glassfish can't found the local EJB or can't consume
I read this:
According to the JavaEE tutorial, the client of a @Local bean "must run in the same JVM as the enterprise bean it accesses."
In the first ear,
I have the local Interface inside a jar
@Local
public interface MyLocalBean {
int getNumber(int num3);
}
In another jar, I have the implementation
@Stateless
@LocalBean
public class MyLocalBeanImpl implements MyLocalBean,Serializable{
public MyLocalBeanImpl() {}
public int getNumber(int num3){......
In the second ear,
in the same Glassfish
I have the local Interface inside a jar
@Local
public interface MyLocalBean {
int getNumber(int num3);
}
In another jar, I have the consumer
@Stateless
@LocalBean
public class BeanConsumer{
@EJB(name="MyLocalBeanImpl")
private MyLocalBean beanlocal;
with @EJB and (name="MyLocalBeanImpl") parameter the error is:
Cannot resolve reference Local ejb-ref name=MyLocalBeanImpl,Local 3.x
interface =my.package.MyLocalBean,ejb-link=null,lookup=,
mappedName=,jndi-name=,refType=Session|#]
with @EJB and (name="my.package.MyLocalBeanImpl") parameter the error is:
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|#]***
I tried too with mappedName
@Stateless(name="MyLocalBeanImpl",mappedName ="MyLocalBeanImpl")
public class MyLocalBeanImpl implements MyLocalBean{
@EJB(name="MyLocalBeanImpl",mappedName ="MyLocalBeanImpl")
private MyLocalBean beanlocal;
but the error persist
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 works with a JNDI like
java:global[/<app-name>]/<module-name>/<bean-name>
I added the annotation @LocalBean to the bean MyLocalBeanImpl
@Stateless
@LocalBean
public class MyLocalBeanImpl implements MyLocalBean{
public MyLocalBeanImpl() {}
public int getNumber(int num3){......
and when I deployed Glassfish say the jndi are two
Portable JNDI names for EJB OtroBean
java:global/myfirstear/myejbs/MyLocalBeanImpl!my.package.MyLocalBeanImpl
and
java:global/myfirstear/myejbs/MyLocalBeanImpl!my.package.MyLocalBean
i'm trying with
@EJB(lookup="java:global/myfirstear/myejbs/MyLocalBeanImpl!my.package.MyLocalBeanImpl")
It seems that Glassfish found the Local Bean, but... Glassfish have problems casting o something like this
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__
And trying with
@EJB(lookup="java:global/myfirstear/myejbs/MyLocalBeanImpl")
I get:
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}
解决方案 It is possible to inject a local EJB into another EJB in the same JVM but different ear.
The problem is that you cannot rely on the name of the bean anymore as you need to tell the consumer bean the complete JNDI name. You can find this name in the server logs during deployment; the moment the bean is bound to the JNDI directory the server shows it in the logs.
这篇关于消耗本地EJB,在同一容器但不同的耳朵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!