Problems with CDI + Weld in Wildfly

Asked

Viewed 557 times

0

I’m trying to create a EntityManagerProducer and it seems in the examples found on the internet something very simple, but it is not being.

So I conclude that I am doing something wrong follows my coding and configuration. Ah my web.xml has no configuration as it is only an API.

BEAN.XML

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
       version="1.1" bean-discovery-mode="all">

</beans>

Entitymanagerproducer

@ApplicationScoped
public class EntityManagerProducer implements Serializable {

    private static final long serialVersionUID = 1L;

    @PersistenceUnit(unitName = "ProjetoFinalPU")
    private EntityManagerFactory appFactory;

    @Produces
    @BancoPadrao
    public EntityManager createAppEntityManager() {
        return appFactory.createEntityManager();
    }

    public void closeEntityManager(@Disposes EntityManager manager) {
        if (manager.isOpen()) {
            manager.close();
        }
    }    
}

Ramodal

public class RamoDal implements Serializable {

    @Inject
    @BancoPadrao
    private EntityManager entityManager;

    public Ramo salvar(Ramo entidade) {
        entityManager.persist(entidade);
        return entidade;
    }

    public Ramo atualizar(Ramo entidade) {
        entityManager.merge(entidade);
        return entidade;
    }

    public List<Ramo> listar() {
        return entityManager.createQuery("select e from Ramo e").getResultList();
    }

    public void remover(Ramo entidade) {
        entityManager.remove(entidade);
    }

}

Bancopadrao

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD,ElementType.METHOD})
public @interface BancoPadrao {

}

Error:

13:58:57,527 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 1) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {
    "WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"proptotipobackend-1.0.war\".WeldStartService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"proptotipobackend-1.0.war\".WeldStartService: Failed to start service
    Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type EntityManager with qualifiers @BancoPadrao
  at injection point [BackedAnnotatedField] @Inject @BancoPadrao private com.mycompany.proptotipobackend.dal.RamoDal.entityManager
  at com.mycompany.proptotipobackend.dal.RamoDal.entityManager(RamoDal.java:0)
"},

I’ve tried to change the scopes to replace the @PersistenceUnit and the error persists.

1 answer

0

Remove these lines from your configuration file (standalone.xml):

<extension module="org.jboss.as.jsf"/>

And

<subsystem xmlns="urn:jboss:domain:jsf:1.0"/>
  • I did what you said and the mistake persisted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.