1
votes

I am trying to deploy my application on my Wildfly 11 server, but am having the following problem.

Cannot upload deployment: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"javaee-angularjs.war\".WeldStartService" => "Failed to start service Caused by: java.lang.IllegalArgumentException: WFLYWELD0037: Error injecting persistence unit into CDI managed bean. Can't find a persistence unit named 'siscorp' in deployment javaee-angularjs.war for injection point private javax.persistence.EntityManager br.com.rafaelvicio.siscorp.util.Persistence.entityManager"}}

this is my persistence class:

package br.com.rafaelvicio.siscorp.util;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@ApplicationScoped
public class Persistence {

      @PersistenceContext(unitName="siscorp")
      private EntityManager entityManager;

      @Produces
      public EntityManager getEntityManager() {
          return entityManager;
      }

}

this is my persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">

    <persistence-unit name="siscorp">

        <!-- provedor/implementacao do JPA -->
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

        <!-- entidade mapeada -->
        <class>br.com.rafaelvicio.siscorp.model.CEP</class>

        <properties>
            <!-- dados da conexao -->
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/siscorp" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="admin123" />

            <!-- propriedades do hibernate -->
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />

            <!-- atualiza o banco, gera as tabelas se for preciso -->
            <property name="hibernate.hbm2ddl.auto" value="update" />

        </properties>
    </persistence-unit>
</persistence>
1
please update the question adding the file tree of your project. You persistente.xml can be in wrong directory.Henrique Fernandes Cipriano
@HenriqueFernandesCipriano github.com/rafaelvicio/CEP-rest this is my tree of project.Rafael Augusto

1 Answers

6
votes

You are getting this error because the persistence.xml file is not built into your WAR file.

This is because you have placed it in the src/main/java directory and it is a Maven project.

Unless you deliberately configure it otherwise (not recommended), Maven only processes .java source files in src/main/java and nothing else.

You must move the META-INF directory and its content from src/main/java to src/main/resources.

Kudos to @Henrique for asking the right question