we have mixed the usage of CDI and EJB in our application. At startup, we receive the error Caused by: org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped
.
We don't understand where exactly the problem is, so here is just the overall structure of the code:
@Stateless
public class SomeFacade {
@Inject
private SomeService someService;
}
@Stateless
public class SomeService {
@Inject
private SomeDao someDao;
}
@Stateless
public class SomeDao {
@Inject
private EntityManager entityManager;
}
@ApplicationScoped
public class EntityManagerProducer {
@Produces
@ApplicationScoped
public EntityManagerFactory createEntityManagerFactory() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("one");
return emf;
}
public void close(@Disposes EntityManagerFactory entityManagerFactory) {
entityManagerFactory.close();
}
@Produces
public EntityManager createEntityManager(EntityManagerFactory entityManagerFactory) {
return entityManagerFactory.createEntityManager();
}
}
Is there something we can change in general?
Ondrej, your answer was helpful but was not quite the solution in my case.
First, I somehow resolved the start-up issues, but received the same error when handling arriving messages / REST requests. The solution was to annotate the service class with @ActivateRequestContext
. This enabled CDI injections in all classes that are used by the servive.