Definitely this solution. Let me quote :
The correct solution is to enter javax.enterprise.inject.Instance, where T is the type of class to introduce. Since the type is directly Foo, calling the get () method on an object typed as an instance is guaranteed to enter the correct object all the time. This approach works very well, because the instance is dynamically obtained from the container by the implementation itself and only as necessary. Therefore, the responsibility for finding dependencies rests with your code - your code is responsible for not making an endless loop.
@Named public class Foo implements Fooable{ @Inject private Instance<Foo> foo; public void executeFirst(){ foo.get().executeSecond(); } @Transactional public void executeSecond(){
user1930502
source share