我们在应用程序中混合使用了 CDI 和 EJB。在启动时,我们收到错误Caused by: org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped
。
我们不明白问题到底出在哪里,所以这里只是代码的整体结构:
@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();
}
}
有什么我们可以改变的吗?