Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple instances of EJB 3.1 no-interface Singleton / Stateful session bean
    primarykey
    data
    text
    <p>I want to access multiple instances <code>singletonA</code> and <code>singletonB</code> of a no-interface Singleton <code>MySingleton</code>. The instances are first defined in another Singleton <code>Configurator</code> class:</p> <p><strong>MySingleton.java</strong></p> <pre><code>@Singleton @LocalBean public class MySingleton { ... } </code></pre> <p><strong>Configurator.java</strong></p> <pre><code>@Singleton @Startup @LocalBean public class Configurator { @EJB MySingleton singletonA; @EJB MySingleton singletonB; } </code></pre> <p>The code above, appearently works.</p> <p>Now, I need to inject these 2 instances of MySingleton in a Message-Driven Bean:</p> <p><strong>MDB.class</strong></p> <pre><code>@Stateless public class MDB implements MessageListener { @EJB (lookup="?") MySingleton singletonA; @EJB (mappedName="??") MySingleton singletonB; } </code></pre> <p>But at this point I am completely lost. I know that I could make things simpler by defining the 2 instances as 2 (empty) implementations of a unique interface. But I have some problems because the class contains some non static fields, so I can't define it as an Interface.</p> <p><strong>EDIT</strong></p> <p>Because of the nature of MDB, I can't pass the Singletons by reference. Finally, I would like to avoid creating two identical implementations of MySingleton.</p> <p>Thanks to the answers received I have been rethinking at the whole architecture and I must agree on the fact that having MySingleton defined as Stateful would be fine as well.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload