title: @Inject returning null (NPE)
body: <p>In my JSF web application, in my client converter class, even using the @Inject annotatoin, my variable that points to the service class, is returning null (NPE).</p>
  
  <p>Follow the converter class code:</p>
  
  <pre><code>@FacesConverter(value = "clienteConverter")
  public class ClienteConverter implements Converter {
  
    @Inject
    private ClienteService clienteService;
  
    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
      if (string == null || string.length() == 0 || string.startsWith("-")) {
        return null;
      }
      try {
        Integer id = Integer.parseInt(string);
        return clienteService.findById(id); // NPE here
      } catch (NumberFormatException | ConverterException e) {
        FacesUtils.error("Erro no converter: " + e.getMessage());
        throw new ConverterException("Erro de conversão do JSF - Valor " + string + " não conversível", e);
      }
    }
  </code></pre>
  
  <p>My dependencies are:</p>
  
  <pre><code>  &lt;dependencies&gt;
      &lt;!-- Usado para geração de PDFs --&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;com.lowagie&lt;/groupId&gt;
        &lt;artifactId&gt;itext&lt;/artifactId&gt;
        &lt;version&gt;2.1.7&lt;/version&gt;
      &lt;/dependency&gt;    
  
      &lt;!-- Usado para geração de arquivos Excel --&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
        &lt;artifactId&gt;poi&lt;/artifactId&gt;
        &lt;version&gt;3.8&lt;/version&gt;
        &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;    
  
      &lt;!-- PrimeFaces (biblioteca de componentes) --&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.primefaces&lt;/groupId&gt;
        &lt;artifactId&gt;primefaces&lt;/artifactId&gt;
        &lt;version&gt;5.3&lt;/version&gt;
        &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- PrimeFaces Themes --&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.primefaces.themes&lt;/groupId&gt;
        &lt;artifactId&gt;bootstrap&lt;/artifactId&gt;
        &lt;version&gt;1.0.10&lt;/version&gt;
        &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Mojarra (implementacao do JSF) --&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.glassfish&lt;/groupId&gt;
        &lt;artifactId&gt;javax.faces&lt;/artifactId&gt;
        &lt;version&gt;2.2.9&lt;/version&gt;
        &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Weld (implementação do CDI) --&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.jboss.weld.servlet&lt;/groupId&gt;
        &lt;artifactId&gt;weld-servlet&lt;/artifactId&gt;
        &lt;version&gt;2.3.2.Final&lt;/version&gt;
        &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Implementacao do Bean Validation --&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
        &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
        &lt;version&gt;5.2.3.Final&lt;/version&gt;
        &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Núcleo do Hibernate --&gt;            
      &lt;dependency&gt;
        &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
        &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
        &lt;version&gt;5.1.0.Final&lt;/version&gt;
        &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Implementação de EntityManager da JPA --&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
        &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
        &lt;version&gt;5.1.0.Final&lt;/version&gt;
        &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;    
  
      &lt;!-- Driver JDBC do MySQL --&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;mysql&lt;/groupId&gt;
        &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
        &lt;version&gt;5.1.38&lt;/version&gt;
        &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- API de Servlet --&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
        &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
        &lt;version&gt;3.1.0&lt;/version&gt;
        &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Commons Lang (utilidades) --&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;commons-lang&lt;/groupId&gt;
        &lt;artifactId&gt;commons-lang&lt;/artifactId&gt;
        &lt;version&gt;2.6&lt;/version&gt;
      &lt;/dependency&gt;    
    &lt;/dependencies&gt;
  </code></pre>
  
  <p>ClienteService.java follows:</p>
  
  <pre><code>package br.com.inovasoftware.erp.web.atbimoveis.service;
  
  import br.com.inovasoftware.erp.web.atbimoveis.model.Cliente;
  import br.com.inovasoftware.erp.web.atbimoveis.repository.ClienteRepository;
  import br.com.inovasoftware.erp.web.atbimoveis.util.Transacional;
  import java.io.Serializable;
  import java.util.List;
  import javax.inject.Inject;
  
  /**
   *
   * @author Leonardo Rocha
   */
  public class ClienteService implements Serializable {
    private static final long serialVersionUID = 1L;
  
    @Inject
    private ClienteRepository clienteRepository;
  
    @Transacional
    public void salvar(Cliente cliente) {
      clienteRepository.gravar(cliente);
    }
  
    @Transacional
    public void excluir(Cliente cliente) {
      clienteRepository.remover(cliente);
    }
  
    public Cliente findById(Integer id) {
      return clienteRepository.findById(id);
    }
  
    public List&lt;Cliente&gt; findByNomeOuCpf(String filtro) {
      return clienteRepository.findByNomeOuCpf(filtro);
    }  
  
    public List&lt;Cliente&gt; findAll() {
      return clienteRepository.findAll();
    }
  </code></pre>
  
  <p>}</p>