Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Unable to access CDI ao iniciar o servidor de aplicação

Olá,

Estou acompanhando os módulos I e II do curso de JSF 2 e uso o mesmo projeto do eclipse e servidor de aplicação desde o começo, entretanto, após aplicar as configurações para CDI o servidor de aplicação não iniciou mais.

Segue log do erro:

... trecho de log omitido ...
20:11:56,591 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0005: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
20:11:56,593 INFO  [org.jboss.weld.deployer] (MSC service thread 1-1) WFLYWELD0006: Starting Services for CDI deployment: jsf-sandbox.war
20:11:56,636 INFO  [org.jboss.weld.Version] (MSC service thread 1-1) WELD-000900: 2.2.14 (Final)
20:11:56,688 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0018: Started Driver service with driver-name = jsf-sandbox.war_com.mysql.jdbc.Driver_5_1
20:11:56,698 INFO  [org.jboss.weld.deployer] (MSC service thread 1-3) WFLYWELD0009: Starting weld service for deployment jsf-sandbox.war
20:11:56,899 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 58) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'jsf-sandbox.war#jsfsandbox'
20:11:57,002 INFO  [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 58) HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
20:11:57,233 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 58) HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
20:11:57,306 INFO  [org.jboss.as.protocol] (XNIO-1 I/O-2) WFLYPRT0057:  cancelled task by interrupting thread Thread[management-handler-thread - 3,5,management-handler-thread]
20:11:57,423 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 58) HHH000397: Using ASTQueryTranslatorFactory
20:11:57,766 INFO  [org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 58) HHH000228: Running hbm2ddl schema update
... trecho de log do hibernate omitido ...
20:11:57,798 INFO  [org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 58) HHH000232: Schema update complete
20:11:58,910 INFO  [org.jboss.weld.environment.servletWeldServlet] (ServerService Thread Pool -- 60) WELD-ENV-001008: Initialize Weld using ServletContainerInitializer
20:11:58,977 INFO  [org.jboss.weld.Bootstrap] (ServerService Thread Pool -- 60) WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
20:11:59,039 INFO  [org.jboss.weld.environment.servletUndertow] (ServerService Thread Pool -- 60) WELD-ENV-001300: Undertow detected, CDI injection will be available in Servlets.
20:11:59,234 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 60) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./jsf-sandbox: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./jsf-sandbox: java.lang.RuntimeException: java.lang.IllegalStateException: Unable to access CDI
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:85)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: Unable to access CDI
    at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:224)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82)
    ... 6 more
Caused by: java.lang.IllegalStateException: Unable to access CDI
    at javax.enterprise.inject.spi.CDI.current(CDI.java:65)
    at org.jboss.weld.servlet.WeldInitialListener.contextInitialized(WeldInitialListener.java:97)
    at org.jboss.weld.servlet.api.helpers.ForwardingServletListener.contextInitialized(ForwardingServletListener.java:34)
    at org.jboss.weld.environment.servlet.EnhancedListener.onStartup(EnhancedListener.java:65)
    at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:184)
    ... 8 more

20:11:59,243 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "jsf-sandbox.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./jsf-sandbox" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./jsf-sandbox: java.lang.RuntimeException: java.lang.IllegalStateException: Unable to access CDI
    Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: Unable to access CDI
    Caused by: java.lang.IllegalStateException: Unable to access CDI"}}
20:11:59,331 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "jsf-sandbox.war" (runtime-name : "jsf-sandbox.war")
20:11:59,332 INFO  [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0186:   Services which failed to start:      service jboss.undertow.deployment.default-server.default-host./jsf-sandbox: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./jsf-sandbox: java.lang.RuntimeException: java.lang.IllegalStateException: Unable to access CDI

20:11:59,719 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
20:11:59,720 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
20:11:59,721 ERROR [org.jboss.as] (Controller Boot Thread) WFLYSRV0026: WildFly Full 9.0.1.Final (WildFly Core 1.0.1.Final) started (with errors) in 12320ms - Started 583 of 766 services (2 services failed or missing dependencies, 221 services are lazy, passive or on-demand)

Servidor de Aplicação: wildfly-9.0.1.Final

Web App Libraries:

all-themes-1.0.10.jar
antlr-2.7.7.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-core-4.1.8.Final.jar
hibernate-entitymanager-4.1.8.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate-validator-4.3.0.Final.jar
javassist-3.15.0-GA.jar
javax.faces-2.2.13.jar
jboss-logging-3.1.0.GA.jar
jboss-transaction-api_1.1_spec-1.0.0.Final.jar
mysql-connector-java-5.1.22-bin.jar
primefaces-6.0.jar
validation-api-1.0.0.GA.jar
weld-servlet-2.3.5.Final.jar

Arquivo context.xml na pasta WebContent/META-INF com o seguinte conteúdo:

<?xml version="1.0" encoding="UTF-8"?>
<Context>
   <Resource name="BeanManager"
      auth="Container"
      type="javax.enterprise.inject.spi.BeanManager"
      factory="org.jboss.weld.resources.ManagerObjectFactory"/>
</Context>

Arquivo beans.xml na pasta WebContent/WEB-INF com o seguinte conteúdo:

<beans>
</beans>

Todos as classes Beans implementando Serializable e imports do CDI:

import javax.faces.view.ViewScoped;
import javax.inject.Named;

@Named
@ViewScoped
public class AutorBean implements Serializable {
    // trecho de código omitido
}
import javax.faces.view.ViewScoped;
import javax.inject.Named;

@Named
@ViewScoped
public class LivroBean implements Serializable {
    // trecho de código omitido
}
import javax.faces.view.ViewScoped;
import javax.inject.Named;

@Named
@ViewScoped
public class VendasBean implements Serializable {
    // trecho de código omitido
}
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named
@SessionScoped
public class LoginBean implements Serializable {
    // trecho de código omitido
}
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named
@SessionScoped
public class TemaBean implements Serializable {
    // trecho de código omitido
}

Observação: Adicionei o server Apache Tomcat v8.0 no Eclipse, alterei a Server Library da aplicação para usar o Apache Tomcat V8.0, adicionei a aplicação no Tomcat e o server levantou sem erros.

Não estou encontrando o motivo do erro no WildFly. Alguém pode me explicar?

2 respostas
solução!

Oi Diego,

nesse curso tem um video dedicado a configuração do projeto com Wildfly. Vc já assistiu esse video?

abs

Oi Nico,

Acabei abrindo essa dúvida no começo do curso pois ainda não havia chegado no vídeo sobre configuração do projeto usando Wildfly. Após configurar o projeto conforme explicado, a aplicação subiu.

Obrigado.