Bean CDI with @Sessionscoped initializes more than once

Asked

Viewed 150 times

1

I created a bean CDI with session scope (@SessionScoped). The problem is that it is going through the constructor several times, and it should only be once while the user is logged in, correct?

I’ve already changed the constructor to a method (@PostConstruct), but did not resolve.

With this, the attributes that should be initialized only once, are being initialized several times, giving errors such as nullpointer.

I’m using CDI with JSF, Primefaces 6, JPA and Wildfly 10.

    package br.com.transportesalvorada.security.controll;

    import java.io.IOException;
    import java.util.Collection;

    import javax.annotation.PostConstruct;
    import javax.enterprise.context.SessionScoped;
    import javax.faces.context.FacesContext;
    import javax.inject.Named;

    import org.primefaces.model.menu.MenuModel;
    import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
    import org.springframework.security.core.GrantedAuthority;

    import br.com.transportesalvorada.security.bean.util.CriaMenus;
    import br.com.transportesalvorada.security.bean.util.ManipulacaoProperties;
    import br.com.transportesalvorada.security.configall.UsuarioSistema;
    import br.com.transportesalvorada.securityadmin.util.FacesUtil;
    import java.io.Serializable;

    @Named
    @SessionScoped
    public class SecurityControllerLogado implements Serializable {

        private static final long serialVersionUID = 1L;

        private Long idLogado = 0L;
        private UsuarioSistema usuarioLogado;
        private String grupos = "";
        private MenuModel menu;
        private String versao = "";

// corpo do bean

}
No answers

Browser other questions tagged

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