0

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.demo.Repository.CarRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

@Repository
public interface CarRepository extends JpaRepository<Car, Long> {
    Optional<Car> findById(Long car);
}
@Service
public class CarServiceImpl implements CarService {

    private final CarRepository carRepository;

    public CarServiceImpl(CarRepository carRepository) {
        this.carRepository = carRepository;
    }

    @Override
    public Car findById(Long id) {
        return carRepository.findById(id).
                orElseThrow(() -> new EntityNotFoundException());
    }

}

The repository does not get recognized as an autowire candidate. It is not about right anotations, but could not figure it out. What should I do to make carRepository get recognized?

I submitted repository and service classes and the annotation error I am getting when I run my application. I expect to get a correction on how to get carRepository get recognized.

0 Answers0