Deploying EJB dependencies of a remote service does not work on Glassfish

I cannot get dependency injection to work with my remote service, and I cannot understand why. I need an instance of RemoteService, so I wrote.

@EJB(name="RemoteService") private RemoteService service; 

And the Bean itself is defined using mappedName = "RemoteService:

 @Stateless(mappedName = "RemoteService") public class RemoteServiceBean implements RemoteService 

When I try to run this code, I get an InjectionException:

 EJB5070: Exception creating stateless session bean : [{0}] com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref RemoteService@jndi: service.remote.RemoteService@null@service.remote.RemoteService@Session@null into class service.OrderServiceBean at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:387) at com.sun.enterprise.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:206) at com.sun.enterprise.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:127) at com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:538) at com.sun.ejb.containers.StatelessSessionContainer.access$100(StatelessSessionContainer.java:111) at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:783) at com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:199) at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:489) at com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:1709) at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1238) at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:195) at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:83) at $Proxy766.size(Unknown Source) at 

I don't have ejb configuration files, but I don't need them, right? The remote service runs on the same glassfish instance as the service trying to reference it. Checking the JNDI Browser in the Glassfish Administrator verifies that the EJBs are deployed with the correct jndi name, and if I remove the @EJB annotation and manually search in the constructor, it also works:

 public OrderServiceBean() { try { final Properties properties = new Properties(); properties.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory"); properties.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming"); properties.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl"); properties.setProperty("org.omg.CORBA.ORBInitialHost", "localhost"); properties.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); final InitialContext initialContext = new InitialContext(properties); this.service = (RemoteService) initialContext.lookup("RemoteService"); } 

Ideas?

+2
java dependency-injection glassfish
Sep 23 2018-10-15T00:
source share
1 answer

I can’t believe that I didn’t try, but it seems I didn’t, I obviously didn’t try to reference the EJB via mappedName. Therefore, changing the link to this makes it work:

 @EJB(mappedName="RemoteService") private RemoteService service; 
+1
Sep 24 2018-10-11T00:
source share



All Articles