IllegalLoopbackException: Cannot call a method on a singleton session bean while constructing the bean instance

StackOverflow https://stackoverflow.com/questions/19572143

  •  01-07-2022
  •  | 
  •  

質問

I'm getting the following exception:

Exception data: javax.ejb.IllegalLoopbackException: Cannot call a method on a singleton session bean while constructing the bean instance : MyWar.war#BarProducer

My code is as follows.

I have a Stateless Session Bean that Injects both Foo and Bar.

@Stateless
public class MySessBean {

    @Inject
    private Foo foo;

    @Inject
    private Bar bar;

    public SomeData myMethod1(...){
        //does something with Foo
        foo.xyz();
    }

    public SomeData myMethod2(...){
        //does something with Bar
        bar.xyz();
    }   

}

I have a producer that creates the Singleton Foo:

@Singleton
public class FooProducer {

    @Produces
    public Foo getFoo() {
         return new Foo();
    }
}

I have another producer that creates the Singleton Bar. In order to create Bar I need to Inject Foo:

@Singleton
public class BarProducer {

    @Inject
    private Foo foo;

    @Produces
    public Bar getBar() {
            //uses Foo
        foo.xyz();
    }
}

I'm using WebSphere 8 (OpenWebBeans). I figured the container would know it needs to craete Foo singleton before it create Bar singleton??

役に立ちましたか?

解決

you're not actually using CDI here. This is an EJB issue. The problem is that you're not specifying a @DependsOn for your EJBs. See here: http://docs.oracle.com/javaee/6/api/javax/ejb/DependsOn.html

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top