1

我正在尝试为我的项目运行 Arquillian 测试,但无法正常工作。我正在使用 CDI、EJB、Hibernate 和 JBoss-AS-7.1.0 服务器。

我有这样的课程:

public interface AppManager {
    Customer findCustomer(String id);
    Customer saveCustomer(Customer entity);
}

实现

@Local(AppManager.class)
@Stateless
public class AppManagerBean implements AppManager {
    @Inject
    EntityManager em;  // injecting from producer class

    @Override
    public Customer findCustomer(String id) {
        Customer result = null;
        try {
            result = em.find(Customer.class, id);
        } catch (NoResultException ignored) {}
        return result;
    }

    @Override
    public Customer saveCustomer(Customer entity) {
        if (null == entity.getLastModified()) em.persist(entity);
        else entity = em.merge(entity);
        return entity;
    }
}

测试看起来像这样:

@RunWith(Arquillian.class)
public class CustomerRegistrationTest {
    @Inject
    AppManagerBean manager; 

    @Deployment
    public static WebArchive createTestArchive() {
        return ShrinkWrap.create(WebArchive.class, "test.war")
        // adding classes omitted
        .addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml")
        .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"))
        .addAsWebInfResource("test-ds.xml");
    }

    @Test
    public void testRegister() throws Exception {
        Customer jack = new Customer("some_string_id", "Jack", "ex@example.com");
        manager.saveCustomer(jack);
        assertEquals("Jack", manager.findCustomer("some_string_id").getName());
    }
}

当我尝试运行测试时,出现异常:

   org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies
 for type [ManagerBean] with qualifiers [@Default] at injection point [[field]
 @Inject com.example.ejb.CustomerRegistrationTest.manager]

我试图用其他说明符注入类,但这毫无意义。这个错误是所有可能结果中最简单的。

更新:

Arquillian.xml

<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://jboss.org/schema/arquillian
    http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

    <defaultProtocol type="Servlet 3.0" />

    <container qualifier="jboss" default="true">    
   </container>
</arquillian>

如果我注入接口

@EJB
private AppManager manager;

我得到了这个巨大的错误日志:

14:00:30,454 ERROR [org.jboss.ejb3.invocation] (http-localhost-127.0.0.1-8080-1) JBAS014134: EJB Invocation failed on component AppManagerBean for method public abstract com.example.model.Customer com.example.ejb.AppManager.saveCustomer(com.example.model.Customer): javax.ejb.EJBException: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance
      at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:166) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:230) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165) [jboss-as-ee-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:173) [jboss-as-ee-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72) [jboss-as-ee-7.1.0.Final.jar:7.1.0.Final]
      at com.example.ejb.AppManager$$$view5.saveCustomer(Unknown Source) [classes:]
      at com.example.rest.CustomerRegistrationTest.testRegister(CustomerRegistrationTest.java:76) [classes:]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_25]
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) [arquillian-junit.jar:]
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) [arquillian-junit.jar:]
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) [arquillian-junit.jar:]
      at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:270) [arquillian-junit.jar:]
      at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:60) [arquillian-core.jar:]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_25]
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94) [arquillian-core.jar:]
      at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99) [arquillian-core.jar:]
      at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81) [arquillian-core.jar:]
      at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135) [arquillian-core.jar:]
      at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115) [arquillian-core.jar:]
      at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67) [arquillian-core.jar:]
      at org.jboss.arquillian.container.test.impl.execution.ContainerTestExecuter.execute(ContainerTestExecuter.java:38) [arquillian-core.jar:]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_25]
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94) [arquillian-core.jar:]
      at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99) [arquillian-core.jar:]
      at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81) [arquillian-core.jar:]
      at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75) [arquillian-core.jar:]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_25]
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94) [arquillian-core.jar:]
      at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88) [arquillian-core.jar:]
      at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60) [arquillian-core.jar:]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_25]
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94) [arquillian-core.jar:]
      at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88) [arquillian-core.jar:]
      at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89) [arquillian-core.jar:]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_25]
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.7.0_25]
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94) [arquillian-core.jar:]
      at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88) [arquillian-core.jar:]
      at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135) [arquillian-core.jar:]
      at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:111) [arquillian-core.jar:]
      at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:263) [arquillian-junit.jar:]
      at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:226) [arquillian-junit.jar:]
      at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314) [arquillian-junit.jar:]
      at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46) [arquillian-junit.jar:]
      at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:240) [arquillian-junit.jar:]
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) [arquillian-junit.jar:]
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) [arquillian-junit.jar:]
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) [arquillian-junit.jar:]
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) [arquillian-junit.jar:]
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) [arquillian-junit.jar:]
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) [arquillian-junit.jar:]
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) [arquillian-junit.jar:]
      at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:185) [arquillian-junit.jar:]
      at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314) [arquillian-junit.jar:]
      at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46) [arquillian-junit.jar:]
      at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199) [arquillian-junit.jar:]
      at org.junit.runners.ParentRunner.run(ParentRunner.java:236) [arquillian-junit.jar:]
      at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147) [arquillian-junit.jar:]
      at org.junit.runner.JUnitCore.run(JUnitCore.java:157) [arquillian-junit.jar:]
      at org.junit.runner.JUnitCore.run(JUnitCore.java:136) [arquillian-junit.jar:]
      at org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:65) [arquillian-junit.jar:]
      at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:160) [arquillian-protocol.jar:]
      at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:126) [arquillian-protocol.jar:]
      at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:90) [arquillian-protocol.jar:]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.10.Final.jar:]
      at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.10.Final.jar:]
      at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:154) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.10.Final.jar:]
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.10.Final.jar:]
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.10.Final.jar:]
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.10.Final.jar:]
      at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_25]
Caused by: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance
      at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:163) [jboss-as-ee-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:85) [jboss-as-ee-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.as.ejb3.component.stateless.StatelessSessionComponent$1.create(StatelessSessionComponent.java:65) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.as.ejb3.component.stateless.StatelessSessionComponent$1.create(StatelessSessionComponent.java:62) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.as.ejb3.pool.AbstractPool.create(AbstractPool.java:60) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.as.ejb3.pool.strictmax.StrictMaxPool.get(StrictMaxPool.java:128) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:47) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]
      ... 112 more
Caused by: java.lang.RuntimeException: Error looking up java:comp/env/com.example.util.GcmSenderProducer/senderId in JNDI
      at org.jboss.weld.injection.spi.helpers.AbstractResourceServices.resolveResource(AbstractResourceServices.java:51) [weld-spi-1.1.Final.jar:20110112-1536]
      at org.jboss.weld.util.Beans.injectEEFields(Beans.java:638) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget$1$1.proceed(ManagedBean.java:160) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget$1.work(ManagedBean.java:157) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.bean.ManagedBean$FixInjectionPoint.run(ManagedBean.java:131) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget.inject(ManagedBean.java:153) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:290) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:61) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:616) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.bean.AbstractReceiverBean.getReceiver(AbstractReceiverBean.java:73) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.bean.ProducerMethod$1.produce(ProducerMethod.java:131) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:299) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:61) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:616) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:681) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:118) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:703) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:712) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.bean.SessionBean$1$1.proceed(SessionBean.java:176) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.bean.SessionBean$1.inject(SessionBean.java:173) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.as.weld.injection.WeldEEInjection.inject(WeldEEInjection.java:78) [jboss-as-weld-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.as.weld.injection.WeldInjectionInterceptor.processInvocation(WeldInjectionInterceptor.java:60) [jboss-as-weld-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.as.ee.component.ManagedReferenceInterceptorFactory$ManagedReferenceInterceptor.processInvocation(ManagedReferenceInterceptorFactory.java:95) [jboss-as-ee-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
      at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:161) [jboss-as-ee-7.1.0.Final.jar:7.1.0.Final]
      ... 120 more
Caused by: javax.naming.NameNotFoundException: env/com.example.util.GcmSenderProducer/senderId -- service jboss.naming.context.java.module.test.test.env."com.example.util.GcmSenderProducer".senderId
      at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
      at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:177)
      at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:123)
      at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:213)
      at javax.naming.InitialContext.lookup(Unknown Source) [rt.jar:1.7.0_25]
      at org.jboss.weld.injection.spi.helpers.AbstractResourceServices.resolveResource(AbstractResourceServices.java:47) [weld-spi-1.1.Final.jar:20110112-1536]
      ... 156 more
4

3 回答 3

0

这个问题的答案:

我发现了问题。解决方案是在 Web 存档中插入几个外部库和带有环境条目的 web.xml。

对任何面临类似问题的人来说都是晦涩难懂的,没有太大用处。

您的代码中有错误。这是不正确的:

  @Inject
    AppManagerBean manager; 

为什么?因为您在无状态 bean 中已经声明它是一个提供本地业务接口的 EJB:

@Local(AppManager.class)

因此,如果你想使用无业务接口@Inject EJB,一旦你使用了@Local 接口,你需要用

@LocalBean 

注解。

这将解决您解决@Inject WELD-001408 异常的问题。

一旦你的 bean 被注释:@LocalBean 你应该能够@Inject 实现类。您还应该被允许声明@Local 业务接口,方法是像您正在做的那样将@Local 注释放在本地bean 上,或者只是通过实现已经包含@Local 注释的业务接口。

于 2016-12-19T14:57:11.287 回答
-1

您的存档内容如何?例如,您可以在部署过程中使用archive.toString(true). 你也可以分享你的 arquillian.xml 吗?我个人建议使用 Servlet 协议,因为它比 AS 7 的默认协议 JMX 更有用。

于 2013-08-19T07:27:26.360 回答
-1

我发现了问题。解决方案是在 Web 存档中插入几个外部库和带有环境条目的 web.xml。

于 2013-08-21T14:22:44.017 回答