Problem with Beans in spring : No Qualifying bean of type

Asked

Viewed 2,676 times

2

I’m having the following problem with the Beans in spring:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'agrupamentoTaxonomiaController' defined in file [D:\IBGE\workspaces\Agatha\adaptacao-RedHat-OpenShift\agatha\codigo-fonte\servico\target\classes\br\gov\mpog\gestaoriscos\controller\AgrupamentoTaxonomiaController.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [br.gov.mpog.gestaoriscos.servico.AgrupamentoTaxonomiaService]: Error creating bean with name 'agrupamentoTaxonomiaServiceImpl' defined in file [D:\IBGE\workspaces\Agatha\adaptacao-RedHat-OpenShift\agatha\codigo-fonte\servico\target\classes\br\gov\mpog\gestaoriscos\servico\impl\AgrupamentoTaxonomiaServiceImpl.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [br.gov.mpog.gestaoriscos.repositorio.AgrupamentoTaxonomiaRepository]: No qualifying bean of type [br.gov.mpog.gestaoriscos.repositorio.AgrupamentoTaxonomiaRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [br.gov.mpog.gestaoriscos.repositorio.AgrupamentoTaxonomiaRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'agrupamentoTaxonomiaServiceImpl' defined in file [D:\IBGE\workspaces\Agatha\adaptacao-RedHat-OpenShift\agatha\codigo-fonte\servico\target\classes\br\gov\mpog\gestaoriscos\servico\impl\AgrupamentoTaxonomiaServiceImpl.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [br.gov.mpog.gestaoriscos.repositorio.AgrupamentoTaxonomiaRepository]: No qualifying bean of type [br.gov.mpog.gestaoriscos.repositorio.AgrupamentoTaxonomiaRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [br.gov.mpog.gestaoriscos.repositorio.AgrupamentoTaxonomiaRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

Taxonomiarepository

    package br.gov.mpog.gestaoriscos.repositorio;

    import br.gov.mpog.gestaoriscos.modelo.AgrupamentoTaxonomia;
    import org.springframework.data.jpa.repository.JpaRepository;

    /**
     * Spring Data JPA repository for the AgrupamentoTaxonomia entity.
     */
    public interface AgrupamentoTaxonomiaRepository extends JpaRepository<AgrupamentoTaxonomia, Long>{
    }

AgrupamentoTaxonomiaCustomRepositorioImpl

@Repository
public class AgrupamentoTaxonomiaCustomRepositorioImpl implements AgrupamentoTaxonomiaCustomRepositorio{

    @Autowired
    private JpaContext jpaContext;

    //RESTO DO CÓDIGO ...
}

Would anyone like to tell me how to solve it? Apparently @Autowired and class types are defined and the class Repository too.

EDIT

Grouping taxonomiacontroller

@RestController
@RequestMapping(value = "/agrupamentotaxonomias", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class AgrupamentoTaxonomiaController {

    private final Logger log = LoggerFactory.getLogger(AgrupamentoTaxonomiaController.class);

    private final AgrupamentoTaxonomiaService service;

    @Autowired
    public AgrupamentoTaxonomiaController(AgrupamentoTaxonomiaService service) {
        this.service = service;
    }

    //RESTO DO CÓDIGO...
}

Grouping

/**
 * Service Interface for managing Taxonomia.
 */
public interface AgrupamentoTaxonomiaService {

      //METODOS A SEREM IMPLEMENTADOS EM OUTRA CLASSE
}

AgrupamentoTaxonomiaServiceImpl

/**
 * Service Implementation for managing Taxonomia.
 */
@Service
@Transactional
public class AgrupamentoTaxonomiaServiceImpl implements AgrupamentoTaxonomiaService {

    private final Logger log = LoggerFactory.getLogger(AgrupamentoTaxonomiaServiceImpl.class);

    private final AgrupamentoTaxonomiaRepository agrupamentoTaxonomiaRepository;

    private final TaxonomiaRepository taxonomiaRepository;

    private final StatusTaxonomiaRepository statusTaxonomiaRepository;

    private final TipoTaxonomiaRepository tipoTaxonomiaRepository;

    private final AgrupamentoTaxonomiaCustomRepositorio agrupamentoTaxonomiaCustomRepositorio;

    private final TaxonomiaCustomRepositorio taxonomiaCustomRepositorio;

    private final EventoRepository eventoRepository;

    private final CausaRepository causaRepository;

    private final ConsequenciaRepository consequenciaRepository;

    private final ControleRepository controleRepository;

    private final OrgaoRepository orgaoRepository;

    private final EventoRiscoRepository eventoRiscoRepository;

    private final EventoCausaRepository eventoCausaRepository;

    private final EventoConsequenciaRepository eventoConsequenciaRepository;

    private final ControleEventoRepository controleEventoRepository;

    private final PlanoControleRepository planoControleRepository;

    private final EventoCustomRepositorio eventoCustomRepositorio;

    private final CausaCustomRepositorio causaCustomRepositorio;

    private final ConsequenciaCustomRepositorio consequenciaCustomRepositorio;

    private final ControleCustomRepositorio controleCustomRepositorio;

    private final AgrupamentoTaxonomiaMapper agrupamentoTaxonomiaMapper;

    private final TipoTaxonomiaMapper tipoTaxonomiaMapper;

    private final TaxonomiaMapper taxonomiaMapper;

    private final EventoMapper eventoMapper;

    private final CausaMapper causaMapper;

    private final ConsequenciaMapper consequenciaMapper;

    private final ControleMapper controleMapper;

    @Autowired
    public AgrupamentoTaxonomiaServiceImpl(AgrupamentoTaxonomiaRepository agrupamentoTaxonomiaRepository, CausaRepository causaRepository, TaxonomiaRepository taxonomiaRepository, StatusTaxonomiaRepository statusTaxonomiaRepository, TipoTaxonomiaRepository tipoTaxonomiaRepository, AgrupamentoTaxonomiaCustomRepositorio agrupamentoTaxonomiaCustomRepositorio, TaxonomiaCustomRepositorio taxonomiaCustomRepositorio, ControleCustomRepositorio controleCustomRepositorio, EventoRepository eventoRepository, PlanoControleRepository planoControleRepository, EventoCausaRepository eventoCausaRepository, ConsequenciaRepository consequenciaRepository, AgrupamentoTaxonomiaMapper agrupamentoTaxonomiaMapper, TaxonomiaMapper taxonomiaMapper, ControleRepository controleRepository, EventoCustomRepositorio eventoCustomRepositorio, ConsequenciaCustomRepositorio consequenciaCustomRepositorio, EventoConsequenciaRepository eventoConsequenciaRepository, OrgaoRepository orgaoRepository, ControleEventoRepository controleEventoRepository, EventoRiscoRepository eventoRiscoRepository, CausaCustomRepositorio causaCustomRepositorio, TipoTaxonomiaMapper tipoTaxonomiaMapper, EventoMapper eventoMapper, CausaMapper causaMapper, ConsequenciaMapper consequenciaMapper, ControleMapper controleMapper) {
        this.agrupamentoTaxonomiaRepository = agrupamentoTaxonomiaRepository;
        this.causaRepository = causaRepository;
        this.taxonomiaRepository = taxonomiaRepository;
        this.statusTaxonomiaRepository = statusTaxonomiaRepository;
        this.tipoTaxonomiaRepository = tipoTaxonomiaRepository;
        this.agrupamentoTaxonomiaCustomRepositorio = agrupamentoTaxonomiaCustomRepositorio;
        this.taxonomiaCustomRepositorio = taxonomiaCustomRepositorio;
        this.controleCustomRepositorio = controleCustomRepositorio;
        this.eventoRepository = eventoRepository;
        this.planoControleRepository = planoControleRepository;
        this.eventoCausaRepository = eventoCausaRepository;
        this.consequenciaRepository = consequenciaRepository;
        this.agrupamentoTaxonomiaMapper = agrupamentoTaxonomiaMapper;
        this.taxonomiaMapper = taxonomiaMapper;
        this.controleRepository = controleRepository;
        this.eventoCustomRepositorio = eventoCustomRepositorio;
        this.consequenciaCustomRepositorio = consequenciaCustomRepositorio;
        this.eventoConsequenciaRepository = eventoConsequenciaRepository;
        this.orgaoRepository = orgaoRepository;
        this.controleEventoRepository = controleEventoRepository;
        this.eventoRiscoRepository = eventoRiscoRepository;
        this.causaCustomRepositorio = causaCustomRepositorio;
        this.tipoTaxonomiaMapper = tipoTaxonomiaMapper;
        this.eventoMapper = eventoMapper;
        this.causaMapper = causaMapper;
        this.consequenciaMapper = consequenciaMapper;
        this.controleMapper = controleMapper;
    }
    //resto do código

}

I posted only the basics that does not show the rules of business because it is a company software.

  • Enter your controller code agrupamentoTaxonomiaController and AgrupamentoTaxonomiaService

4 answers

1


The application Mappers were in the constructor and the @Autowired annotation tried to inject them as dependencies. This was causing the problem, after taking them out of the constructor of each class the application worked normally.

0

Add the following annotation to the main class:

@EnableJpaRepositories("br.gov.mpog.gestaoriscos.repositorio");
  • Didn’t work. :/

  • @Pedroteixeira updated the answer

  • Hasn’t worked yet.

0

/**
 * Service Interface for managing Taxonomia.
 */
@Service
public interface AgrupamentoTaxonomiaService {

      //METODOS A SEREM IMPLEMENTADOS EM OUTRA CLASSE
}

Try inserting @Service into the Interface if you are referencing it in your Controller.

  • It’s already in the Grouping Taxonomy I just put up there.

  • @Pedroteixeira pq is exactly creating an implementation for Repository?

  • This project belongs to the company. I don’t know who did it, I was asked to change as little as possible. Also do not know what was the purpose, believed to be some design Pattern.

0

What may be happening is that when the controller tries to instantiate the class AgrupamentoTaxonomiaServiceImpl it cannot because there is only one constructor method in this class, which requires the passage of parameters. What can solve your problem is to delete the constructor from the class AgrupamentoTaxonomiaServiceImpl and put the @Autowired on top of each class attribute to be made dependency injection.

  • Still giving error, but changed the end of it: No qualifying bean of type [br.gov.mpog.gestaoriscos.servico.mapper.AgrupamentoTaxonomiaMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

  • try to mark this class with @Component, or create a bean for her.

Browser other questions tagged

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