在 OpenEjb 和带有嵌入式容器的 Junit 的帮助下,我为我的 Java-ee 项目创建了一些单元测试和集成测试。测试在 Eclipse 中运行良好,bean(CDI/EJB)被注入并且工作正常。但是当我用 maven 和 surefire 开始测试时,我得到了以下错误:
WARNING: Handling the following exception
Throwable occurred: javax.enterprise.context.ContextNotActiveException: WebBeans context with scope type annotation @RequestScoped does not exist within current thread
at org.apache.webbeans.container.BeanManagerImpl.getContext(BeanManagerImpl.java:330)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:88)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.get(NormalScopedBeanInterceptorHandler.java:70)
at org.apache.webbeans.conversation.ConversationImpl$$OwbNormalScopeProxy0.isTransient(org/apache/webbeans/conversation/ConversationImpl.java)
at org.apache.wicket.cdi.ConversationPropagator.onUrlMapped(ConversationPropagator.java:322)
at org.apache.wicket.request.cycle.RequestCycleListenerCollection$9.notify(RequestCycleListenerCollection.java:208)
有什么问题?它看起来像一个类路径问题或其他东西,但显式添加 openwebbeans-spi 和 openwebbeans-impl 不起作用。
我在测试类中使用以下几行:
@ClassRule
public static final EJBContainerRule CONTAINER_RULE = new EJBContainerRule();
@Rule
public final InjectRule rule = new InjectRule(this, CONTAINER_RULE);
我有以下 openejb-junit.properties:
openejb.validation.output.level=VERBOSE
openejb.deployments.classpath.include=.*org.mine.*
openejb.descriptors.output=true
openejb.ejbcontainer.close=single-jvm
java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory
谢谢你的帮助。
问候,胡尔斯。