Spring MVC - Multiple Builders

0

I have a problem where a Framework I'm using needs a default constructor, this is calling my Service class:

@Service
public class FuncionarioService {

private FuncionarioDAO dao;


    public FuncionarioService(){        
    }   

    @Autowired
    public FuncionarioService(FuncionarioDAO dao) {
        this.dao = dao;
    }   

When calling the method below, the variable "dao" is coming "null". When using another path that does not use the Framework, everything is normal, the variable comes different from "null".

public List<Funcionario> obterFuncionarios(Hierarquia hierarquia){
        List<Funcionario> listaFuncionarios = new ArrayList<Funcionario>();
        listaFuncionarios = dao.obterFuncionarios(hierarquia);
        return listaFuncionarios;
    }
    
asked by anonymous 28.09.2018 / 20:29

1 answer

0

You are attempting to instantiate a Spring service object, try using @Autowired to inject this object and see if it works.

When you use an @Service, you are creating a service with reverse control, which can be injected. The moment you try to add or instantiate an object, problems can occur because you theoretically break the control inversion chain.

    
28.09.2018 / 20:36