0

After setup some classes of CDI resources, my app don't build anymore.

Created, model, controller and service to provide a Login System.

Added a Producer to Entity Manager

EntityManagerProducer.java

package br.com.sys.util;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

@ApplicationScoped

public class EntityManagerProducer {
    private EntityManagerFactory factory;
    public EntityManagerProducer() {
        this.factory = Persistence.createEntityManagerFactory(
                "SistemaPU");
    }
    @Produces
    @RequestScoped
    public EntityManager createEntityManager() {
        return factory.createEntityManager();
    }
    public void closeEntityManager(@Disposes EntityManager manager) {
        manager.close();
    }
}

In package src.main.resources.META-INF: beans.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/javae/beans_1_1.xsd"
    bean-discovery-mode="all">
</beans>

My Model Usuario.java

package br.com.sys.model;

import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.io.Serializable;
import java.util.Objects;

@Named
@SessionScoped
@Entity
public class Usuario implements Serializable {
    private static final long serialVersionUID = 7371518231621030644L;

    @Id @GeneratedValue
    private Long id;
    private String usuario;
    private String senha;
    private String nome;
    private Long perfil;
    private String cpf;
    private String email;


    public boolean isLogado() {
        return nome != null;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsuario() {
        return usuario;
    }

    public void setUsuario(String usuario) {
        this.usuario = usuario;
    }

    public String getSenha() {
        return senha;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public Long getPerfil() {
        return perfil;
    }

    public void setPerfil(Long perfil) {
        this.perfil = perfil;
    }

    public String getCpf() {
        return cpf;
    }

    public void setCpf(String cpf) {
        this.cpf = cpf;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Usuario usuario = (Usuario) o;
        return Objects.equals(id, usuario.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}

My Controller LoginBean.java

package br.com.sys.controller;

import br.com.sys.model.Usuario;
import br.com.sys.repository.Usuarios;
import br.com.sys.service.Logins;
import br.com.ufs.sys.util.JpaUtil;

import javax.faces.application.FacesMessage;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;

@Named
@RequestScoped
public class LoginBean {

    @Inject
    private Logins dologin;

/*    @Inject
    private Usuarios usuarios;
*/
    private Usuario user = new Usuario();
    private String usuario;
    private String password;


    public String login() {
        EntityManager manager = JpaUtil.getEntityManager();
        try {
            this.user = dologin.autenticar(this.usuario);
        }
        catch (Exception e){
            e.printStackTrace();
        }
        finally {
            manager.close();
        }
        FacesContext context = FacesContext.getCurrentInstance();
        if (this.usuario.equals(this.user.getUsuario())
                && this.password.equals(this.user.getSenha())) {

            return "/ConsultaLancamentos?faces-redirect=true";

        } else {
            FacesMessage mensagem = new FacesMessage(
                    "Usuário/senha inválidos!");
            mensagem.setSeverity(FacesMessage.SEVERITY_ERROR);
            context.addMessage(null, mensagem);
        }
        return null;
    }

    public String logout() {
        FacesContext.getCurrentInstance().getExternalContext()
                .invalidateSession();
        return "/Login?faces-redirect=true";
    }

    public Logins getDologin() {
        return dologin;
    }

    public void setDologin(Logins dologin) {
        this.dologin = dologin;
    }

    public Usuario getUser() {
        return user;
    }

    public void setUser(Usuario user) {
        this.user = user;
    }

    public String getUsuario() {
        return usuario;
    }

    public void setUsuario(String usuario) {
        this.usuario = usuario;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

Using this Service

Logins.java

package br.com.sys.service;

import br.com.sys.model.Usuario;
import br.com.sys.repository.Usuarios;


import javax.inject.Inject;
import java.io.Serializable;

public class Logins implements Serializable {
    private static final long serialVersionUID = 1L;

    @Inject
    private Usuarios usuarios;

    public void salvar(Usuario usuario) throws NegocioException {
        if (usuario.getUsuario() != null) {
            throw new NegocioException(
                    "Usuario vazio ou já existente");
        }
        this.usuarios.adicionar(usuario);
    }

    public Usuario autenticar(String user) throws NegocioException{
        return usuarios.porUsuario(user);
    }
}

And this repository class Usuarios.java

package br.com.sys.repository;

import br.com.sys.model.Usuario;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;
import java.io.Serializable;
import java.util.List;

public class Usuarios implements Serializable {
    private static final long serialVersionUID = 1L;

    private EntityManager manager;

    @Inject
    public Usuarios(EntityManager manager) {
        this.manager = manager;
    }

    public Usuario porUsuario(String usuario) throws NoResultException {
        TypedQuery<Usuario> query = manager.createQuery("SELECT user FROM Usuario user WHERE user.usuario = :parUser",Usuario.class);
        query.setParameter("parUser",usuario);
        return query.getSingleResult();
    }
    public List<Usuario> todas() {
        TypedQuery<Usuario> query = manager.createQuery(
                "from Usuario", Usuario.class);
        return query.getResultList();
    }

    public void adicionar(Usuario usuario) {
        EntityTransaction trx = this.manager.getTransaction();
        trx.begin();
        this.manager.persist(usuario);
        trx.commit();
    }
}

Login.xhtml:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>Login</title>
    <h:outputStylesheet library="css" name="estilo.css" />
</h:head>
<h:body>
    <div id="login-dialog">
        <h1>Login</h1>
        <h:form id="frm">
            <p:messages/>
            <p:autoUpdate/>
            <h:panelGrid columns="2" styleClass="grid-login">
                <p:outputLabel value="Usuário" for="usuario" />
                <p:inputText id="usuario" size="20"
                             value="#{loginBean.usuario}" />
                <p:outputLabel value="Senha" for="senha" />
                <p:password id="senha" size="20"
                            value="#{loginBean.password}" />
                <p:outputLabel />
                <p:commandButton value="Acessar"
                                 action="#{loginBean.login}" />
            </h:panelGrid>
        </h:form>
    </div>
</h:body>
</html>

Log Output:

=========================================================================
...
08:59:31,861 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-5) WFLYDS0013: Started FileSystemDeploymentService for directory /home/caio/wildfly-17.0.0.Final/standalone/deployments
08:59:32,326 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-7) WFLYUT0006: Undertow HTTPS listener https listening on 127.0.0.1:8443
08:59:32,663 INFO  [org.jboss.ws.common.management] (MSC service thread 1-6) JBWS022052: Starting JBossWS 5.3.0.Final (Apache CXF 3.3.2) 
08:59:32,952 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0212: Resuming server
08:59:32,966 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
08:59:32,967 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
08:59:32,967 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 17.0.0.Final (WildFly Core 9.0.1.Final) started in 12258ms - Started 314 of 576 services (369 services are lazy, passive or on-demand)
Connected to server
[2019-07-08 08:59:33,534] Artifact sistema:war exploded: Artifact is being deployed, please wait...
08:59:33,806 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) WFLYSRV0027: Starting deployment of "sistema_war_exploded" (runtime-name: "sistema_war_exploded.war")
08:59:38,663 INFO  [org.jboss.as.jpa] (MSC service thread 1-6) WFLYJPA0002: Read persistence.xml for SistemaPU
08:59:39,509 INFO  [org.jboss.weld.deployer] (MSC service thread 1-8) WFLYWELD0003: Processing weld deployment sistema_war_exploded.war
08:59:39,759 INFO  [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-5) ISPN000128: Infinispan version: Infinispan 'Infinity Minus ONE +2' 9.4.14.Final
08:59:39,812 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-8) HV000001: Hibernate Validator 6.0.16.Final
08:59:40,074 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 76) WFLYJPA0010: Starting Persistence Unit (phase 1 of 2) Service 'sistema_war_exploded#SistemaPU'
08:59:40,103 INFO  [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 76) HHH000204: Processing PersistenceUnitInfo [
    name: SistemaPU
    ...]
08:59:40,343 INFO  [org.hibernate.Version] (ServerService Thread Pool -- 76) HHH000412: Hibernate Core {5.3.10.Final}
08:59:40,351 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 76) HHH000206: hibernate.properties not found
08:59:40,937 INFO  [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 76) HCANN000001: Hibernate Commons Annotations {5.0.5.Final}
08:59:41,191 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 10) WFLYCLINF0002: Started client-mappings cache from ejb container
08:59:41,523 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-7) WFLYJCA0005: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 42.2)
08:59:41,568 INFO  [org.jboss.weld.Version] (MSC service thread 1-7) WELD-000900: 3.1.1 (Final)
08:59:41,707 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-6) WFLYJCA0018: Started Driver service with driver-name = sistema_war_exploded.war_org.postgresql.Driver_42_2
08:59:42,098 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 76) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'sistema_war_exploded#SistemaPU'
08:59:42,141 WARN  [org.hibernate.orm.connections.pooling] (ServerService Thread Pool -- 76) HHH10001002: Using Hibernate built-in connection pool (not for production use!)
08:59:42,144 INFO  [org.hibernate.orm.connections.pooling] (ServerService Thread Pool -- 76) HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost/postgres]
08:59:42,145 INFO  [org.hibernate.orm.connections.pooling] (ServerService Thread Pool -- 76) HHH10001001: Connection properties: {user=postgres, password=****}
08:59:42,146 INFO  [org.hibernate.orm.connections.pooling] (ServerService Thread Pool -- 76) HHH10001003: Autocommit mode: false
08:59:42,151 INFO  [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (ServerService Thread Pool -- 76) HHH000115: Hibernate connection pool size: 20 (min=1)
08:59:42,562 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 76) HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL9Dialect
08:59:42,850 INFO  [org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl] (ServerService Thread Pool -- 76) HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
08:59:42,862 INFO  [org.hibernate.type.BasicTypeRegistry] (ServerService Thread Pool -- 76) HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@1c2ad0f0
08:59:42,874 INFO  [org.hibernate.envers.boot.internal.EnversServiceImpl] (ServerService Thread Pool -- 76) Envers integration enabled? : true
08:59:44,465 WARN  [org.jboss.weld.Bootstrap] (MSC service thread 1-3) WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class com.sun.faces.flow.FlowDiscoveryCDIHelper is deprecated from CDI 1.1!
08:59:44,476 INFO  [io.smallrye.metrics] (MSC service thread 1-3) MicroProfile: Metrics activated
08:59:47,293 INFO  [org.jboss.weld.environment.servletWeldServlet] (ServerService Thread Pool -- 76) WELD-ENV-001008: Initialize Weld using ServletContainerInitializer
08:59:47,328 INFO  [org.jboss.weld.Bootstrap] (ServerService Thread Pool -- 76) WELD-ENV-000020: Using jandex for bean discovery
08:59:47,350 WARN  [org.jboss.weld.environment.deployment.discovery.DefaultBeanArchiveScanner] (ServerService Thread Pool -- 76) Unable to adapt URL: vfs:/home/caio/IdeaProjects/sistema/out/artifacts/sistema_war_exploded/WEB-INF/classes/META-INF/beans.xml, using its external form instead
08:59:47,365 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 76) MSC000001: Failed to start service jboss.deployment.unit."sistema_war_exploded.war".undertow-deployment: org.jboss.msc.service.StartException in service jboss.deployment.unit."sistema_war_exploded.war".undertow-deployment: java.lang.RuntimeException: java.lang.NullPointerException
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:81)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
    at java.lang.Thread.run(Thread.java:748)
    at org.jboss.threads.JBossThread.run(JBossThread.java:485)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
    at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:252)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:96)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:78)
    ... 8 more
Caused by: java.lang.NullPointerException
    at org.jboss.weld.environment.deployment.discovery.jandex.JandexFileSystemBeanArchiveHandler.handle(JandexFileSystemBeanArchiveHandler.java:43)
    at org.jboss.weld.environment.deployment.discovery.AbstractDiscoveryStrategy.performDiscovery(AbstractDiscoveryStrategy.java:87)
    at org.jboss.weld.environment.servlet.WeldServletLifecycle.createDeployment(WeldServletLifecycle.java:230)
    at org.jboss.weld.environment.servlet.WeldServletLifecycle.initialize(WeldServletLifecycle.java:120)
    at org.jboss.weld.environment.servlet.EnhancedListener.onStartup(EnhancedListener.java:61)
    at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:203)
    at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:185)
    at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
    at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
    at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)
    at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:250)
    ... 10 more

08:59:47,376 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 1) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "sistema_war_exploded")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"sistema_war_exploded.war\".undertow-deployment" => "java.lang.RuntimeException: java.lang.NullPointerException
    Caused by: java.lang.RuntimeException: java.lang.NullPointerException
    Caused by: java.lang.NullPointerException"}}
08:59:47,382 ERROR [org.jboss.as.server] (management-handler-thread - 1) WFLYSRV0021: Deploy of deployment "sistema_war_exploded.war" was rolled back with the following failure message: 
{"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"sistema_war_exploded.war\".undertow-deployment" => "java.lang.RuntimeException: java.lang.NullPointerException
    Caused by: java.lang.RuntimeException: java.lang.NullPointerException
    Caused by: java.lang.NullPointerException"}}
08:59:47,390 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) WFLYJCA0019: Stopped Driver service with driver-name = sistema_war_exploded.war_org.postgresql.Driver_42_2
08:59:47,470 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 15) WFLYJPA0011: Stopping Persistence Unit (phase 2 of 2) Service 'sistema_war_exploded#SistemaPU'
08:59:47,474 INFO  [org.hibernate.orm.beans] (ServerService Thread Pool -- 15) HHH10005004: Stopping BeanContainer : org.hibernate.resource.beans.container.internal.CdiBeanContainerExtendedAccessImpl@1593c593
08:59:47,476 INFO  [org.hibernate.orm.connections.pooling] (ServerService Thread Pool -- 15) HHH10001008: Cleaning up connection pool [jdbc:postgresql://localhost/postgres]
08:59:47,496 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 15) WFLYJPA0011: Stopping Persistence Unit (phase 1 of 2) Service 'sistema_war_exploded#SistemaPU'
08:59:47,607 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) WFLYSRV0028: Stopped deployment sistema_war_exploded (runtime-name: sistema_war_exploded.war) in 228ms
[2019-07-08 08:59:47,699] Artifact sistema:war exploded: Error during artifact deployment. See server log for details.
[2019-07-08 08:59:47,699] Artifact sistema:war exploded: java.lang.Exception: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"sistema_war_exploded.war\".undertow-deployment" => "java.lang.RuntimeException: java.lang.NullPointerException
    Caused by: java.lang.RuntimeException: java.lang.NullPointerException
    Caused by: java.lang.NullPointerException"}}
  • 1
    Your question is confusing. You posted 6 custom files. Are you indeed implying that the web application deploys successfully when you remove only one of these? This seems strange to me. If it indeed still errors out when removing a specific file, then you don't at all need to include it in your question in order to make the question and the problem more clear and better focused. Repeat the same for the remaining files until you end up with the absolute minimum required code in order to reproduce the problem. In other words .. debug yourself first! See also https://stackoverflow.com/help/mcve – BalusC Jul 08 '19 at 14:32
  • This bug appear when I changed the old "User" JSF managed beans to implement the CDI beans. I'm tried a lot debug this problem, but not found solution. Because this, i come search for a help. Understand me? – Caio Alexandre Jul 08 '19 at 15:29
  • we understand that you came here for help. But posting a lot of code (too much) does not help. Narrow things down first by creating a [mcve]. That is the basic thing in debugging/root cause analysis. – Kukeltje Jul 08 '19 at 17:24
  • 1
    Could https://issues.jboss.org/browse/WELD-2038 help? Jboss mentions that they fixed a bug in weld: 2.2.16.SP1, 3.0.0.Alpha13, 2.3.0.Final resulting in weld: 2.3.1.Final, 3.0.0.Alpha14, 2.2.x. Sadly they don't mention any causes or workarounds – aschoerk Jul 09 '19 at 14:14
  • Btw making an entity also a managed bean is not right: https://stackoverflow.com/questions/25431338/why-shouldnt-entity-bean-be-managed-by-jsf-framework and https://stackoverflow.com/questions/8463178/what-to-use-managed-beans-backing-beans-or-entity-beans and https://stackoverflow.com/questions/10301363/jpa-entity-as-jsf-bean – Kukeltje Jul 09 '19 at 20:42
  • Just a suggestion: change bean-discovery-mode of your beans.xml file to annotated nstead of "all", and make sure all your CDI beans are properly annotated. bean. This usually avoids many unwanted clashes and helps to keep control of where and when a bean can be used. – Paulo Araújo Apr 06 '20 at 21:30

0 Answers0