2

In my application, I have the following startup bean:

@Startup
@Singleton
@DependsOn("RecordAcumulator")
public class StartupBean {
    private static final Logger logger = Logger.getLogger(StartupBean.class);

    @Inject
    RecordAcumulator recordAcumulator;

    /**
     * Initializes the EJB system on the post construct event
     */
    @PostConstruct
    public void init() {

The record accumulator is an EJB that accesses the database. The startup is intended to preload database tables into the cache.

@Stateless
public class RecordAcumulator {

When this launches, I get

Caused by: com.ibm.ws.exception.RuntimeWarning: CNTR0200E: The StartupBean singleton session bean in the EJB.jar module depends on the RecordAcumulator enterprise bean in the EJB.jar, but the target is not a singleton session bean.

I have tried many variations of this and I can't seem to get the thing to inject. My log file indicates that the RecordAcumulator EJB was bound prior to the startup bean being loaded, so I can't figure out why I can't inject the EJB into my startup.

If I remove the @DependsOn I get this:

Caused by: javax.ejb.NoSuchEJBException: An error occurred during initialization of singleton session bean bla#EJB.jar#StartupBean, resulting in the discarding of the singleton instance.; nested exception is: javax.ejb.EJBException: The @Inject java.lang.reflect.Field.recordAcumulator reference of type com.foo.bar.accum.RecordAcumulator for the StartupBean component in the EJB.jar module of the bla application cannot be resolved.

Any ideas how to pull this off?

EDIT---------- I found this link: Controlling CDI Startup inside EJB 3.1

But the issue with that is i'm using WAS 8.5.5.0, That issue was supposed to be resolved in 8.5.0.2

Community
  • 1
  • 1
scphantm
  • 4,293
  • 8
  • 43
  • 77

1 Answers1

0

From what I can see:

  1. Remove the @DependsOn
  2. Make your EJB @Singleton

There can be complexities with singleton EJBs, as all the traffic going through your application will go through that one instance. In your case that may not be an issue.

Community
  • 1
  • 1
Rob Grant
  • 7,239
  • 4
  • 41
  • 61
  • Problem with that is the RecordAcumulator EJB is the most heavily used class in the system. Its even called multiple times in the same function in parallel with WAS work manager threads. I don't want to make that a singleton as I need the transaction isolation features of the EJB – scphantm May 13 '15 at 12:41
  • Ah okay, that danger is what I was mentioning, above. Didn't get that impression from your question :) Sorry. – Rob Grant May 13 '15 at 12:51