Já tinha achado que estava muito preso ao TOMCAT e conceitualmente acreditava que iria funcionar a aplicação CDI sem ser amarrado ao TOMCAT, eis que está amarrado.
No inicio do capitulo 3, baixei o exercicio do Nico, criei nova workspace e não mudei nada. Somente mudei no BuildPath para wildFly e RunTimeTarget para WildFly que funcionou em todos capitulos e cursos de Jsf, mas CDI não funciona e esta amarrado a estrutura para TOMCAT e conceitualmente deveria funcionar para outros servidores.
Abaixo o erro sem mudanças
Como resolver isso?
Com context.xml do NICO
21:21:12,103 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 2) WFLYDS0004: Found livraria.war in deployment directory. To trigger deployment create a file called livraria.war.dodeploy
21:21:12,138 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0027: Starting deployment of "livraria.war" (runtime-name: "livraria.war")
21:21:13,888 WARN [org.jboss.weld.deployer] (MSC service thread 1-4) WFLYWELD0012: Warning while parsing vfs:/C:/wildfly-9.0.2.Final/standalone/deployments/livraria.war/WEB-INF/beans.xml:1 cvc-elt.1: Não pode localizar a declaração do elemento 'beans'.
21:21:13,903 INFO [org.jboss.as.jpa] (MSC service thread 1-4) WFLYJPA0002: Read persistence.xml for livraria
21:21:14,093 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 61) WFLYJPA0010: Starting Persistence Unit (phase 1 of 2) Service 'livraria.war#livraria'
21:21:14,101 INFO [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 61) HHH000204: Processing PersistenceUnitInfo [
name: livraria
...]
21:21:14,158 INFO [org.hibernate.Version] (ServerService Thread Pool -- 61) HHH000412: Hibernate Core {4.3.10.Final}
21:21:14,160 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 61) HHH000206: hibernate.properties not found
21:21:14,161 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 61) HHH000021: Bytecode provider name : javassist
21:21:14,340 INFO [org.jboss.weld.deployer] (MSC service thread 1-3) WFLYWELD0003: Processing weld deployment livraria.war
21:21:14,389 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-3) HV000001: Hibernate Validator 5.1.3.Final
21:21:14,807 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0005: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
21:21:14,809 INFO [org.jboss.weld.deployer] (MSC service thread 1-3) WFLYWELD0006: Starting Services for CDI deployment: livraria.war
21:21:14,838 INFO [org.jboss.weld.Version] (MSC service thread 1-3) WELD-000900: 2.2.16 (SP1)
21:21:14,875 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) WFLYJCA0018: Started Driver service with driver-name = livraria.war_com.mysql.jdbc.Driver_5_1
21:21:14,878 INFO [org.jboss.weld.deployer] (MSC service thread 1-2) WFLYWELD0009: Starting weld service for deployment livraria.war
21:21:15,037 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 61) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'livraria.war#livraria'
21:21:15,104 INFO [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 61) HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
21:21:15,308 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 61) HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
21:21:15,601 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 61) HHH000397: Using ASTQueryTranslatorFactory
21:21:15,892 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 61) HHH000228: Running hbm2ddl schema update
21:21:15,892 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 61) HHH000102: Fetching database metadata
21:21:15,896 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 61) HHH000396: Updating schema
21:21:15,901 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 61) HHH000262: Table not found: Autor
21:21:15,902 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 61) HHH000262: Table not found: Livro
21:21:15,903 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 61) HHH000262: Table not found: Livro_Autor
21:21:15,904 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 61) HHH000262: Table not found: Usuario
21:21:15,905 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 61) HHH000262: Table not found: Autor
21:21:15,906 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 61) HHH000262: Table not found: Livro
21:21:15,906 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 61) HHH000262: Table not found: Livro_Autor
21:21:15,907 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 61) HHH000262: Table not found: Usuario
21:21:15,908 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 61) HHH000262: Table not found: Autor
21:21:15,908 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 61) HHH000262: Table not found: Livro
21:21:15,909 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 61) HHH000262: Table not found: Livro_Autor
21:21:15,910 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 61) HHH000262: Table not found: Usuario
21:21:15,911 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 61) HHH000262: Table not found: hibernate_sequence
21:21:15,919 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 61) HHH000232: Schema update complete
21:21:15,919 WARN [org.hibernate.internal.SessionFactoryImpl] (ServerService Thread Pool -- 61) HHH000008: JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()
21:21:16,653 INFO [org.jboss.weld.environment.servletWeldServlet] (ServerService Thread Pool -- 79) WELD-ENV-001008: Initialize Weld using ServletContainerInitializer
21:21:16,703 INFO [org.jboss.weld.Bootstrap] (ServerService Thread Pool -- 79) WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
21:21:16,732 INFO [org.jboss.weld.environment.servletUndertow] (ServerService Thread Pool -- 79) WELD-ENV-001300: Undertow detected, CDI injection will be available in Servlets.
21:21:16,827 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 79) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./livraria: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./livraria: 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(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
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
21:21:16,832 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 1) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "livraria.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./livraria" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./livraria: 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"}}
21:21:17,057 INFO [org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0010: Deployed "livraria.war" (runtime-name : "livraria.war")
21:21:17,058 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 1) WFLYCTL0183: Service status report
WFLYCTL0186: Services which failed to start: service jboss.undertow.deployment.default-server.default-host./livraria: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./livraria: java.lang.RuntimeException: java.lang.IllegalStateException: Unable to access CDI
Sem Context.xml zerado
21:13:11,938 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 2) WFLYDS0004: Found livraria.war in deployment directory. To trigger deployment create a file called livraria.war.dodeploy
21:13:11,967 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0027: Starting deployment of "livraria.war" (runtime-name: "livraria.war")
21:13:13,697 WARN [org.jboss.weld.deployer] (MSC service thread 1-4) WFLYWELD0012: Warning while parsing vfs:/C:/wildfly-9.0.2.Final/standalone/deployments/livraria.war/WEB-INF/beans.xml:1 cvc-elt.1: Não pode localizar a declaração do elemento 'beans'.
21:13:13,713 INFO [org.jboss.as.jpa] (MSC service thread 1-4) WFLYJPA0002: Read persistence.xml for livraria
21:13:13,909 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 9) WFLYJPA0010: Starting Persistence Unit (phase 1 of 2) Service 'livraria.war#livraria'
21:13:13,917 INFO [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 9) HHH000204: Processing PersistenceUnitInfo [
name: livraria
...]
21:13:13,974 INFO [org.hibernate.Version] (ServerService Thread Pool -- 9) HHH000412: Hibernate Core {4.3.10.Final}
21:13:13,975 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 9) HHH000206: hibernate.properties not found
21:13:13,977 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 9) HHH000021: Bytecode provider name : javassist
21:13:14,155 INFO [org.jboss.weld.deployer] (MSC service thread 1-1) WFLYWELD0003: Processing weld deployment livraria.war
21:13:14,205 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-1) HV000001: Hibernate Validator 5.1.3.Final
21:13:14,633 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)
21:13:14,634 INFO [org.jboss.weld.deployer] (MSC service thread 1-1) WFLYWELD0006: Starting Services for CDI deployment: livraria.war
21:13:14,663 INFO [org.jboss.weld.Version] (MSC service thread 1-1) WELD-000900: 2.2.16 (SP1)
21:13:14,700 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) WFLYJCA0018: Started Driver service with driver-name = livraria.war_com.mysql.jdbc.Driver_5_1
21:13:14,704 INFO [org.jboss.weld.deployer] (MSC service thread 1-4) WFLYWELD0009: Starting weld service for deployment livraria.war
21:13:14,850 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 9) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'livraria.war#livraria'
21:13:14,918 INFO [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 9) HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
21:13:15,305 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 9) HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
21:13:15,412 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 9) HHH000397: Using ASTQueryTranslatorFactory
21:13:15,703 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 9) HHH000228: Running hbm2ddl schema update
21:13:15,704 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 9) HHH000102: Fetching database metadata
21:13:15,708 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 9) HHH000396: Updating schema
21:13:15,713 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 9) HHH000262: Table not found: Autor
21:13:15,714 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 9) HHH000262: Table not found: Livro
21:13:15,715 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 9) HHH000262: Table not found: Livro_Autor
21:13:15,716 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 9) HHH000262: Table not found: Usuario
21:13:15,716 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 9) HHH000262: Table not found: Autor
21:13:15,717 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 9) HHH000262: Table not found: Livro
21:13:15,718 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 9) HHH000262: Table not found: Livro_Autor
21:13:15,718 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 9) HHH000262: Table not found: Usuario
21:13:15,719 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 9) HHH000262: Table not found: Autor
21:13:15,719 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 9) HHH000262: Table not found: Livro
21:13:15,720 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 9) HHH000262: Table not found: Livro_Autor
21:13:15,721 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 9) HHH000262: Table not found: Usuario
21:13:15,722 INFO [java.sql.DatabaseMetaData] (ServerService Thread Pool -- 9) HHH000262: Table not found: hibernate_sequence
21:13:15,730 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 9) HHH000232: Schema update complete
21:13:15,730 WARN [org.hibernate.internal.SessionFactoryImpl] (ServerService Thread Pool -- 9) HHH000008: JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()
21:13:16,435 INFO [org.jboss.weld.environment.servletWeldServlet] (ServerService Thread Pool -- 9) WELD-ENV-001008: Initialize Weld using ServletContainerInitializer
21:13:16,485 INFO [org.jboss.weld.Bootstrap] (ServerService Thread Pool -- 9) WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
21:13:16,517 INFO [org.jboss.weld.environment.servletUndertow] (ServerService Thread Pool -- 9) WELD-ENV-001300: Undertow detected, CDI injection will be available in Servlets.
21:13:16,627 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 9) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./livraria: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./livraria: 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(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
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
21:13:16,632 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 1) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "livraria.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./livraria" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./livraria: 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"}}
21:13:16,999 INFO [org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0010: Deployed "livraria.war" (runtime-name : "livraria.war")
21:13:16,999 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 1) WFLYCTL0183: Service status report
WFLYCTL0186: Services which failed to start: service jboss.undertow.deployment.default-server.default-host./livraria: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./livraria: java.lang.RuntimeException: java.lang.IllegalStateException: Unable to access CDI