Calling an EJB interface within a @Singleton

950 views Asked by At

I'm currently working with Java EE (WildFly 8.0) I have the following classes:

public interface A { 
    public void method(); 
}

It's Implementation

@Stateless
public class  ABean implements A { 
    public void method() { //do stuff} 
}

And a Singleton which has this interface as an EJB

@Singleton
@LocalBean
public class Singleton  { 
    @EJB
    public A a; 
}

Whenever I call Singleton.a.method() within another EJB in my business logic, it throws an InvokationException saying: EJB Invocation failed.

Is there something missing here? I already tried declaring the interface @Local but still the same problem.

1

There are 1 answers

0
jHilscher On

Have you tried wrapping the method call inside a method in the singleton?

@Singleton
@LocalBean
public class TestSingleton  { 

    @Inject
    public ITest a; 


    public void Run() {
        a.Method();
    }
}

This works for me on Wildfly 8.1, while TestSingleton.a.Method() fails with a NullPointer.