0
votes

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; 
   }

}
2

2 Answers

1
votes

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")
0
votes

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 :)