Paul
Paul

Reputation: 163

Lookup using @EJB fails

I'm trying to look up my stateless bean using the annotation class @EJB, but fails. I'm using WildFly 10 as EE container. The stateless bean interface looks as follows:

@Local
public interface T1Service {
    String sayHi();
}

The implementation class:

@Stateless
public class T1ServiceImpl implements T1Service {
    @Override
    public String sayHi() {
        return "Hi!";
    }
}

In my controller I want to inject the service:

@EJB(lookup = "javaee/T1ServiceImpl")
private T1Service t1Service;

Make the call:

t1Service.sayHi();

But it fails with a NullPointerException (t1Service is null).

What am I missing?

Note, the JNDI bindings are:

    java:global/javaee/T1ServiceImpl!p1.T1Service
    java:app/javaee/T1ServiceImpl!p1.T1Service
    java:module/T1ServiceImpl!p1.T1Service
    java:jboss/exported/javaee/T1ServiceImpl!p1.T1Service
    java:global/javaee/T1ServiceImpl
    java:app/javaee/T1ServiceImpl
    java:module/T1ServiceImpl

Upvotes: 0

Views: 153

Answers (1)

Georg Leber
Georg Leber

Reputation: 3580

The controller where you want to inject the T1Service is also a @Stateless Bean? If it is runnning in the same application you can omit the definition of property lookup.

I would also suggest to use CDI (@Inject) in case that you are using Java EE 6/7/8. (see here for more information)

Upvotes: 0

Related Questions