简体   繁体   中英

how can use @EJB with remote interface"

I have glassfish v4 and 2 ears:

  1. Service.ear contains EJBs.
  2. WebApplications.ear contains Web Applications.

I try to use the:

@EJB(mappedName="java:global/Service/allServices/ServiceEJBs!Service1Remote")
Service1Remote service1Remot;

But I got error:

Caused by: com.sun.faces.spi.InjectionProviderException: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=java:global/Service/allServices/ServiceEJBs!Service1Remote,Remote 3.x interface =Service1Remote,ejb-link=null,lookup=,mappedName=global/Service/allServices/ServiceEJBs!Service1Remote,jndi-name=,refType=Session into class com.manage.application.WebApplication: null

But when I user the :

Service1Remote remote= (Service1Remote) new InitialContext().lookup("java:global/Service/allServices/ServiceEJBs!Service1Remote"); 

it works fine.

The EJB:

@Remote
public interface Service1Remote{
   public long getCount(int itemId);
}

@Stateless(name = "ServiceEJBs" , mappedName ="ServiceEJBs")
public Service1Bean implements Service1Remote{
   public long getCount(int itemId){
     ...............
     return 100000999; 
   }

}

Clearly your definition for @EJB(mappedname) differs from the mapped name in @Stateless(mappedNamed) definition.

That said, it wont even work if you replaced the correct mapped name (Cause these are in two different ear deployments).

to actually get a reference, please use

@EJB(lookup="java:global/Service/allServices/ServiceEJBs!Service1Remote")

Instead of

@EJB(mappedName="java:global/Service/allServices/ServiceEJBs!Service1Remote")

I reinstall the latest versions of glassfish 4.1 and JDK1.8.0_25, and as Maress said changed :

@EJB(lookup="java:global/Service/allServices/ServiceEJBs!Service1Remote")

Instead of

@EJB(mappedName="java:global/Service/allServices/ServiceEJBs!Service1Remote")

and now it's working fine.

Thanks Maress :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM