Bug with Bean and @Autowired using Spring

Asked

Viewed 37 times

-3

I’m doing a program for costume rental stores and I’m using Spring Boot.My mistakes are in the controller and dao.

Follow the necessary controller code:

@Controller
public class AluguelController extends HttpServlet {

    @Autowired(required = true)
    private ClienteDao dao;

    @Autowired(required = true)
    private AluguelRepository aluguelRepository;

    @Autowired(required = true)
    private ClienteRepository clienteRepository;

    @Autowired(required = true)
    private RoupaUtensiliosRepository roupaUtensiliosRepository;

    @Autowired(required = true)
    private TipoRoupaRepository tipoRoupaRepository;

    @Autowired(required = true)
    private RoupaUtensiliosDao rdao;

Follow the dao code needed:

public interface ClienteDao {

    List<Cliente> getByNomeCli(String nomeCli);
}

Error shown by intellij:


APPLICATION FAILED TO START


Description:

Field dao in com.vitoria.trajes.controller.Aluguelcontroller required a bean of type 'com.vitoria.dao.Clientedao' that could not be found.

The Injection point has the following Annotations: - @org.springframework.Beans.factory.Annotation.Autowired(required=true)

Action:

Consider Defining a bean of type 'com.vitoria.dao.Clientedao' in your Configuration.

2 answers

-1

For the bean to be created the interface has to be implemented in a concrete class, and in this class have @Repository or @Component in the case of a DAO.

-1

In the project settings, you need to set your class ClienteDao is a bean, you need to define that the package it is in is swept so that spring finds it and understands that it is a bean.

  • I did that and you keep making the same mistake.

Browser other questions tagged

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