猿问

java.lang.RuntimeException:无法注入成员

一段时间以来,我一直在尝试让 Arquillian 与 JPA 一起运行。


我进行了一些 DAO 测试,但是在继续编写剩余的测试时,此错误开始并影响了我正在编写的测试和之前运行良好的测试。


java.lang.RuntimeException:无法注入成员


at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectClass(CDIInjectionEnricher.java:117)

at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.enrich(CDIInjectionEnricher.java:71)

at org.jboss.arquillian.test.impl.TestInstanceEnricher.enrich(TestInstanceEnricher.java:51)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:86)

at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:103)

at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:90)

at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:69)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:86)

at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:95)

at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:83)



紫衣仙女
浏览 106回答 1
1回答

长风秋雁

我认为这个堆栈跟踪中最重要的部分是:WELD-001408:MorphologicalAnalysisPersistenceFacade 类型的不满意依赖项这通常意味着并非MorphologicalAnalysisPersistenceFacade所需的所有依赖项都部署到 Weld 容器。要对此进行调试,我建议暂时将您的部署方法重写为:@Deploymentpublic static Archive<?> createDeployment() {&nbsp; &nbsp; JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "morphological-analysis-data-access-object-test.jar")&nbsp; &nbsp; .addPackages(true, "br.com.cpmh.beacon")&nbsp; &nbsp; .addAsResource("test-persistence.xml", "META-INF/persistence.xml")&nbsp; &nbsp; .addAsResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));&nbsp; &nbsp; // print all included packages&nbsp; &nbsp; System.out.println(archive.toString(true));&nbsp; &nbsp; return archive;}这将打印出部署到容器的所有类。这样,您可以调查是否有任何必需的类没有被部署,并在 createDeployment 方法中手动包含该类或包。
随时随地看视频慕课网APP

相关分类

Java
我要回答