Java CDI Invalid DependsOn dependency

I am trying to update some content in the database at application startup. In order to do so I have created a class A which will do so.

@Singleton
@Startup
@DependsOn({ "B", "C" })
public class A{
    @Inject B b;
    @Inject C c; 
    ...
}

B is a class which reads some configuration values from the database. B:

@Singleton
@Startup
public class B {
     @PersistenceContext
     EntityManager em; 
     ...
}

C is a tree structure which uses the data from classes D and E to construct a correctly formatted tree.
C:

@Singleton
@Startup
@DependsOn({ "D", "E" })
public class QuestionHandler {
     @Inject
     D d;
     @Inject
     E e; 
     ...
 }

D and E are leaf singletons in the sense that they don’t depend on other singletons; They provide data (which is read from files to the db):
D:

@Singleton
@Startup
public class D { ... }

E:

@Singleton
@Startup
public class D { ... }

Based on the DependsOn annotation documentation I assumed that CDI will create the dependency graph for the singletons and will initialize them in the specified order (B, D, and E will be initialized before C will, and before finally A will be initialized). However, when I try to deploy the application, I get an exception telling me:
Exception during lifecycle processing
java.lang.RuntimeException: Invalid DependsOn dependency ‘C’ for EJB ContentUpdater.
Does anyone know why this exception occurs given the structure described above?

When I leave out class C in the @DependsOn annotation in class A, I get another exception, so unfortunately that is not a solution.

Source: java

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.