Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Anotações @Singleton e @PostConstruct na classe Banco

Estou fazendo a atividade 2, da aula 2 de EJB. Anotei a classe Banco com @Stateless e @Singleton e criei um método void aposCriacao() anotado com @PostConstruct. Também injetei a classe Banco com a anotação @Inject na classe AutorDao. Os seguintes erros aparecem no console (meu servidor é o Wildfly10x e a versão Java é o Java SE 8 ).

Não entendo o por que do erro "A component named 'Banco' is already defined in this module ..."

10:46:02,505 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0004: Found livraria.war in deployment directory. To trigger deployment create a file called livraria.war.dodeploy 10:46:02,568 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0027: Starting deployment of "livraria.war" (runtime-name: "livraria.war") 10:46:03,228 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit."livraria.war".PARSE: org.jboss.msc.service.StartException in service jboss.deployment.unit."livraria.war".PARSE: WFLYSRV0153: Failed to process phase PARSE of deployment "livraria.war" at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:154) at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.IllegalArgumentException: WFLYEE0040: A component named 'Banco' is already defined in this module at org.jboss.as.ee.component.EEModuleDescription.addComponent(EEModuleDescription.java:162) at org.jboss.as.ejb3.deployment.processors.EJBComponentDescriptionFactory.addComponent(EJBComponentDescriptionFactory.java:58) at org.jboss.as.ejb3.deployment.processors.SessionBeanComponentDescriptionFactory.processSessionBeans(SessionBeanComponentDescriptionFactory.java:169) at org.jboss.as.ejb3.deployment.processors.SessionBeanComponentDescriptionFactory.processAnnotations(SessionBeanComponentDescriptionFactory.java:98) at org.jboss.as.ejb3.deployment.processors.AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.processAnnotations(AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.java:57) at org.jboss.as.ejb3.deployment.processors.AbstractDeploymentUnitProcessor.deploy(AbstractDeploymentUnitProcessor.java:76) at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:147) ... 5 more

10:46:03,230 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "livraria.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"livraria.war\".PARSE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"livraria.war\".PARSE: WFLYSRV0153: Failed to process phase PARSE of deployment \"livraria.war\" Caused by: java.lang.IllegalArgumentException: WFLYEE0040: A component named 'Banco' is already defined in this module"}} 10:46:03,371 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0010: Deployed "livraria.war" (runtime-name : "livraria.war") 10:46:03,371 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 2) WFLYCTL0183: Service status report WFLYCTL0186: Services which failed to start: service jboss.deployment.unit."livraria.war".PARSE: org.jboss.msc.service.StartException in service jboss.deployment.unit."livraria.war".PARSE: WFLYSRV0153: Failed to process phase PARSE of deployment "livraria.war"

1 resposta
solução!

Retirei a anotação @Stateless da classe Banco, deixando apenas @Singleton e @Startup, e isso resolveu o problema. Não tinha prestado atenção para o fato de que se o Banco é @Singleton, ou seja, se só precisa haver 1 isntância do Banco, não poder/não deve ser @Stateless, ao mesmo tempo, também.