I'm trying to create a EntityManagerProducer
and it seems like in the examples found on the internet something very simple, but it's not being.
Then it concludes that I'm doing something wrong following my coding and configuration. Ah my web.xml
has no configuration because 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)
"},
Already tenti change the scopes replace @PersistenceUnit
and error persists.