1

I have a Stateless Session bean which I want to inject into another Stateless Session Bean (no-interface LocalBean) using @EJB:

@Path("/user")
@LocalBean
@Stateless(mappedName = "ejb/UserServiceRest")
public class UserServiceRest extends BaseServiceFacadeRest<User, String> {

    @EJB(mappedName = "ejb/userService")
    private UserServiceBeanLocal userService;

    public UserServiceRest() {}

public getService() {return userService;}

    // ... etc

The bean being injected is:

@Stateless(mappedName="ejb/UserService")
public class UserServiceBean extends BaseServiceBean<User, String> implements UserServiceBeanRemote, UserServiceBeanLocal {

        public UserServiceBean() {}

// ... etc

now I use the first bean as a REST endpoint for a Jersey JAX-RS based webapp:

@ApplicationPath("/rest")
public class MyPortalApplication extends Application {
    @Override
    public Set<Class<?>> getClasses() {
        final Set<Class<?>> classes = new HashSet<Class<?>>();
        // register root resource
        classes.add(UserServiceRest.class);
        return classes;
    }      
}

after that I hit 127.0.0.1:8080/myapp/rest/user

UserServiceRest is able to handle the incoming request, but the userService field is not instantiated, @EJB is not injecting a UserServiceBeanLocal instance, thus userService is null.

I would like to know what is missing, since I'm injecting it into another EJB it should work as expected.

guilhebl
  • 8,330
  • 10
  • 47
  • 66
  • When you define the mapped name, there is a capital U in ejb/UserService, but when you use it, there is a lower case 'u'. – Mareen Apr 02 '14 at 14:21
  • I removed the (mappedName="ejb/UserService") attribute above and tried using EJB or Inject annotations, both fail, it seems Glassfish has some limitations when integrating Jersey and CDI according to question: http://stackoverflow.com/questions/18963627/how-to-integrate-jax-rs-with-cdi-in-a-servlet-3-0-container – guilhebl Apr 04 '14 at 14:54

0 Answers0