1
votes

I have an EAR application with three modules:

  • beans are in "app-ejb" module
  • remote interfaces are in "app-remote"
  • web services are in "app-war"
  • app-ejb and app-war use app-remote as library.

all are packaged in "app.ear".

This is working fine, but now I have to use the same beans outside the EAR application, and injection is not working.

I have in app-ejb:

@Stateless
@LocalBean
public class Services implements ServicesRemote {
  [...]
}

and his remote interface in app-remote:

@Remote
public interface ServicesRemote {
  [...]
}

In my app-war I can inject the remote bean without problem:

@Stateless
@LocalBean
public class UseServices {
  @EJB
  private ServicesRemote services;
  [...]
}

Anyway in my external ejb application, deployed as stand-alone and using the same ejb-remote as library, if I try to inject the same EJB like this:

@Stateless
@LocalBean
public class UseServicesFromAnotherApp {
  @EJB
  private ServicesRemote services;
  [...]
}

Glassfish (4.1) give me an error "Class [ Lcom/[...]/ServicesRemote; ] not found".

Is this expected? How can I inject the remote bean correctly?

2
can you post the whole log error please ?davidxxx
there's no "whole error log", the only line I get is: [2016-10-31T14:38:47.657-0300] [glassfish 4.1] [SEVERE] [] [global] [tid: _ThreadID=43 _ThreadName=admin-listener(3)] [timeMillis: 1477935527657] [levelValue: 1000] [[ Class [ Lcom/..../ServicesRemote; ] not found. Error while loading [ class com....UseServicesFromAnotherApp ]]]moretti.fabio

2 Answers

2
votes

Injection doesn't work with remote interfaces. Beans that are "injectable", live inside container's JVM and are available for injection to other beans inside the same application. The same holds true for accessing beans in another application in the same container, although applications may live in the same JVM. Since remote methods are originated from another JVM or another application, injection is not possible. You must use JNDI lookup instead to get a reference to a remote bean.

As a matter or personal taste, I would stay away from EJB Remote interfaces, and instead I would use another "remoting" technique such as REST.

0
votes

The problem was probably generated by a number of hot deploys, made glassfish unstable. When I restarted glassfish my code start to work properly (it's actually still working).

Sorry for posting here without trying to restart glassfish first.