java – 使用本地EJB,在同一个Container但不同的耳朵

前端之家收集整理的这篇文章主要介绍了java – 使用本地EJB,在同一个Container但不同的耳朵前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在试图在同一个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}

解决方法

可以将本地EJB注入到同一JVM中的另一个EJB中,但不同之处.

问题是您不能再依赖bean的名称,因为您需要告诉使用者bean完整的JNDI名称.您可以在部署期间在服务器日志中找到此名称;当bean绑定到JNDI目录时,服务器会在日志中显示它.

原文链接:https://www.f2er.com/java/128879.html

猜你在找的Java相关文章