Do I need @Repository annotation when extending CrudRepository (Spring)?

Viewed 895
public interface CarRepository extends CrudRepository<Car, Long> {

    Optional<Car> findByCarId(String carId);

    Iterable<Car> findAllByDealerName(String dealerName);
}

I have the following repository and my program works just fine.

In a lot of tutorials I see however that even when you extend CrudRepository, you should use the @Repository annotation.

Do I need it or not?

1 Answers

No you don't need the @Repository annotation. It is superfluous and does nothing for Spring Data repositories.

Related