Mais ou menos. Toda vez que ele chama o componente ele faz uma consulta no banco.
Fiz assim:
package br.com.netsoft.componente;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.ApplicationScope;
import br.com.netsoft.dto.todos.CnaeDTO;
import br.com.netsoft.servico.todos.CnaeServico;
@Component
@ApplicationScope
public class CnaeComponent {
@Autowired
private CnaeServico cnaeServico;
public Set<CnaeDTO> buscarCnae() {
CnaeDTO dto = new CnaeDTO();
dto.setSonenteCodigosAcimaNove(true);
return cnaeServico.listar(0, 0, dto);
}
}
Controller
package br.com.netsoft.controller.publico;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
import br.com.netsoft.componente.CnaeComponent;
import br.com.netsoft.model.notafiscal.NotaFiscalEntity;
import br.com.netsoft.servico.util.DataUtil;
@Controller
/***
* Controller da página pública de cadastro de contador
*
* @author Guilherme Costa
*/
public class PessoaContadorPreCadastroController extends NotaFiscalServicoController<NotaFiscalEntity> {
private static final long serialVersionUID = 4679349908654563358L;
@Autowired
private CnaeComponent cnaeComponent;
private void cnae(ModelAndView modelAndView) {
modelAndView.addObject("cnaes", cnaeComponent.buscarCnae());
}
}