how can use @EJB with remote interface"
I have glassfish v4 and 2 ears:
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 :)
链接地址: http://www.djcxy.com/p/58784.html下一篇: 如何使用@EJB与远程接口“