无法使用 @inject 在 java 中注入 Gson

Cant inject Gson in java with @inject

你好,我有以下问题,当我在没有@inject private Gson gson 的情况下加载 class 时,它运行正常,但是当我放置它时,它会抛出异常。

Class 调用 gson.

package core.control;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import com.google.gson.Gson;

import core.dao.SistemaDao;
import core.model.Sistema;

@Named
public class SistemaControl {

    private SistemaDao sistemaDao;

    @Inject
    private Gson gson;

    @Inject
    public SistemaControl(SistemaDao sistemaDao) {
        this.sistemaDao = sistemaDao;
    }

    public String getTodosOsSistemas() {
        List<Sistema> sistemas = sistemaDao.buscarTodos();
        String json = "oiii";
        return json;
    }

}

创作者:

package core.control;

import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;

import com.google.gson.Gson;

public class CriadorGson {

    @Produces
    public Gson criarGson() {
        Gson gson = new Gson();
        return gson;
    }

    public void destruir(@Disposes Gson gson) {
        gson = null;
    }

}

调用gson的bean的class

package core.jsfConnection;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

import core.control.SistemaControl;

@Named("sistemaMB")
@RequestScoped
public class SistemaMB {

    @Inject
    private SistemaControl sistemaControl;

    public String getTodosSistemas() {
        String sistemasJson = sistemaControl.getTodosOsSistemas();
        return sistemasJson;
    }

}

异常

GRAVE: CDI Beans module deployment failed
org.apache.webbeans.exception.inject.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [core.control.SistemaControl] is not found with the qualifiers 
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name :  sistemaControl, Bean Owner : [SistemaMB, Name:sistemaMB, WebBeans Type:MANAGED, API Types:[java.lang.Object,core.jsfConnection.SistemaMB], Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default,javax.inject.Named]]
    at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:215)
    at org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(OpenEJBLifecycle.java:194)
    at org.apache.openejb.cdi.ThreadSingletonServiceImpl.initialize(ThreadSingletonServiceImpl.java:160)
    at org.apache.openejb.cdi.CdiBuilder.build(CdiBuilder.java:41)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:797)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:623)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1248)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1087)
    at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:130)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5378)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [core.control.SistemaControl] is not found with the qualifiers 
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name :  sistemaControl, Bean Owner : [SistemaMB, Name:sistemaMB, WebBeans Type:MANAGED, API Types:[java.lang.Object,core.jsfConnection.SistemaMB], Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default,javax.inject.Named]]
    at org.apache.webbeans.util.InjectionExceptionUtil.throwUnsatisfiedResolutionException(InjectionExceptionUtil.java:60)
    at org.apache.webbeans.container.InjectionResolver.checkInjectionPoint(InjectionResolver.java:195)
    at org.apache.webbeans.container.BeanManagerImpl.validate(BeanManagerImpl.java:955)
    at org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:491)
    at org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:422)
    at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:202)
    ... 18 more

Abr 27, 2015 5:53:03 PM org.apache.catalina.core.ContainerBase removeChild
GRAVE: ContainerBase.removeChild: destroy: 
org.apache.catalina.LifecycleException: An invalid Lifecycle transition was attempted ([before_destroy]) for component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/patrimonio]] in state [STARTING_PREP]
    at org.apache.catalina.util.LifecycleBase.invalidTransition(LifecycleBase.java:409)
    at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:299)
    at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:1041)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.undeploy(TomcatWebAppBuilder.java:1524)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.undeploy(TomcatWebAppBuilder.java:1505)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.undeployWebApps(TomcatWebAppBuilder.java:747)
    at org.apache.openejb.assembler.classic.Assembler.destroyApplication(Assembler.java:1668)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:892)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:623)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1248)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1087)
    at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:130)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5378)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

Abr 27, 2015 5:53:03 PM org.apache.openejb.assembler.classic.Assembler destroyApplication
ADVERTÊNCIA: cant unbind resource patrimonio/BeanManager
Abr 27, 2015 5:53:03 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
GRAVE: The web application [/patrimonio] appears to have started a thread named [HSQLDB Timer @50149626] but has failed to stop it. This is very likely to create a memory leak.
Abr 27, 2015 5:53:03 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
GRAVE: The web application [/patrimonio] created a ThreadLocal with key of type [com.sun.xml.bind.v2.runtime.Coordinator] (value [com.sun.xml.bind.v2.runtime.Coordinator@78523259]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@5c67aec5]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Abr 27, 2015 5:53:03 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
GRAVE: The web application [/patrimonio] created a ThreadLocal with key of type [com.sun.xml.bind.v2.ClassFactory] (value [com.sun.xml.bind.v2.ClassFactory@1b0336e8]) and a value of type [java.util.WeakHashMap] (value [{class org.apache.openejb.jee.jpa.unit.Persistence=java.lang.ref.WeakReference@7009c732, class java.util.ArrayList=java.lang.ref.WeakReference@11f4dd15, class org.apache.openejb.jee.jpa.unit.Property=java.lang.ref.WeakReference@62de96e8, class javax.xml.bind.annotation.adapters.CollapsedStringAdapter=java.lang.ref.WeakReference@3858c0e, class org.apache.openejb.jee.jpa.unit.Properties=java.lang.ref.WeakReference@34adecf0, class org.apache.openejb.jee.jpa.unit.PropertiesAdapter=java.lang.ref.WeakReference@69e9b95, class org.apache.openejb.jee.jpa.unit.PersistenceUnit=java.lang.ref.WeakReference@16f85698}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Abr 27, 2015 5:53:03 PM org.apache.tomee.catalina.TomcatWebAppBuilder startInternal
GRAVE: Unable to deploy collapsed ear in war StandardEngine[Catalina].StandardHost[localhost].StandardContext[/patrimonio]
org.apache.openejb.OpenEJBException: Creating application failed: /home/thiago/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/patrimonio: couldn't start owb context
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:896)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:623)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1248)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1087)
    at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:130)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5378)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.openejb.OpenEJBRuntimeException: couldn't start owb context
    at org.apache.openejb.cdi.ThreadSingletonServiceImpl.initialize(ThreadSingletonServiceImpl.java:162)
    at org.apache.openejb.cdi.CdiBuilder.build(CdiBuilder.java:41)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:797)
    ... 14 more
Caused by: org.apache.openejb.OpenEJBRuntimeException: org.apache.webbeans.exception.inject.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [core.control.SistemaControl] is not found with the qualifiers 
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name :  sistemaControl, Bean Owner : [SistemaMB, Name:sistemaMB, WebBeans Type:MANAGED, API Types:[java.lang.Object,core.jsfConnection.SistemaMB], Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default,javax.inject.Named]]
    at org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(OpenEJBLifecycle.java:197)
    at org.apache.openejb.cdi.ThreadSingletonServiceImpl.initialize(ThreadSingletonServiceImpl.java:160)
    ... 16 more
Caused by: org.apache.webbeans.exception.inject.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [core.control.SistemaControl] is not found with the qualifiers 
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name :  sistemaControl, Bean Owner : [SistemaMB, Name:sistemaMB, WebBeans Type:MANAGED, API Types:[java.lang.Object,core.jsfConnection.SistemaMB], Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default,javax.inject.Named]]
    at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:215)
    at org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(OpenEJBLifecycle.java:194)
    ... 17 more
Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [core.control.SistemaControl] is not found with the qualifiers 
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name :  sistemaControl, Bean Owner : [SistemaMB, Name:sistemaMB, WebBeans Type:MANAGED, API Types:[java.lang.Object,core.jsfConnection.SistemaMB], Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default,javax.inject.Named]]
    at org.apache.webbeans.util.InjectionExceptionUtil.throwUnsatisfiedResolutionException(InjectionExceptionUtil.java:60)
    at org.apache.webbeans.container.InjectionResolver.checkInjectionPoint(InjectionResolver.java:195)
    at org.apache.webbeans.container.BeanManagerImpl.validate(BeanManagerImpl.java:955)
    at org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:491)
    at org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:422)
    at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:202)
    ... 18 more

Abr 27, 2015 5:53:03 PM org.apache.catalina.core.ContainerBase startInternal
GRAVE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/patrimonio]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:188)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:816)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/patrimonio]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    ... 6 more
Caused by: org.apache.tomee.catalina.TomEERuntimeException: org.apache.openejb.OpenEJBException: Creating application failed: /home/thiago/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/patrimonio: couldn't start owb context
    at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1257)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1087)
    at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:130)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5378)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 6 more
Caused by: org.apache.openejb.OpenEJBException: Creating application failed: /home/thiago/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/patrimonio: couldn't start owb context
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:896)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:623)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1248)
    ... 12 more
Caused by: org.apache.openejb.OpenEJBRuntimeException: couldn't start owb context
    at org.apache.openejb.cdi.ThreadSingletonServiceImpl.initialize(ThreadSingletonServiceImpl.java:162)
    at org.apache.openejb.cdi.CdiBuilder.build(CdiBuilder.java:41)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:797)
    ... 14 more
Caused by: org.apache.openejb.OpenEJBRuntimeException: org.apache.webbeans.exception.inject.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [core.control.SistemaControl] is not found with the qualifiers 
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name :  sistemaControl, Bean Owner : [SistemaMB, Name:sistemaMB, WebBeans Type:MANAGED, API Types:[java.lang.Object,core.jsfConnection.SistemaMB], Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default,javax.inject.Named]]
    at org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(OpenEJBLifecycle.java:197)
    at org.apache.openejb.cdi.ThreadSingletonServiceImpl.initialize(ThreadSingletonServiceImpl.java:160)
    ... 16 more
Caused by: org.apache.webbeans.exception.inject.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [core.control.SistemaControl] is not found with the qualifiers 
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name :  sistemaControl, Bean Owner : [SistemaMB, Name:sistemaMB, WebBeans Type:MANAGED, API Types:[java.lang.Object,core.jsfConnection.SistemaMB], Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default,javax.inject.Named]]
    at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:215)
    at org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(OpenEJBLifecycle.java:194)
    ... 17 more
Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [core.control.SistemaControl] is not found with the qualifiers 
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name :  sistemaControl, Bean Owner : [SistemaMB, Name:sistemaMB, WebBeans Type:MANAGED, API Types:[java.lang.Object,core.jsfConnection.SistemaMB], Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default,javax.inject.Named]]
    at org.apache.webbeans.util.InjectionExceptionUtil.throwUnsatisfiedResolutionException(InjectionExceptionUtil.java:60)
    at org.apache.webbeans.container.InjectionResolver.checkInjectionPoint(InjectionResolver.java:195)
    at org.apache.webbeans.container.BeanManagerImpl.validate(BeanManagerImpl.java:955)
    at org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:491)
    at org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:422)
    at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:202)
    ... 18 more

Abr 27, 2015 5:53:03 PM org.apache.catalina.core.ContainerBase startInternal
GRAVE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:188)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:739)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:689)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:816)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 6 more

Abr 27, 2015 5:53:03 PM org.apache.catalina.startup.Catalina start
GRAVE: The required Server component failed to start so Tomcat is unable to start.
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:689)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:739)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 11 more

问题不在于 Gson。什么在您的 SistemaMB class 中提供 SistemaControl?从堆栈跟踪来看,它看起来什么都没有。

例如,您可以将 Produces 方法添加到此 class:

public class CriadorModule {

    @Produces
    public SistemaControl criarSistemaControl() {
        return new SistemaControl();
    }

    @Produces
    public Gson criarGson() {
        Gson gson = new Gson();
        return gson;
    }

    // FYI the destroy in your CriadorGson class has no effect, you need to understand how variables work in Java. gson is a local copy of a reference.

}

sistemaControl 似乎无法注入。 @javax.enterprise.inject.Default() 是默认使用的限定符,如果你没有指定任何(在@Inject 旁边)。如果您使用 Java EE 6,请确保您已创建 beans.xml 以启用 CDI(默认情况下,托管 beans 是被注释的 beans,例如 @Named)。如果您使用 Java EE 7 那么...应该启用 CDI;然后确保比 beans.xml 属性 bean-discovery-mode 没有设置为 'none'。

希望对您有所帮助。