2
@Repository
public interface RoomRepository extends CrudRepository<Room, Long>{
    Room findByNumber(String number);
}

I have the RoomRepository above

@Service
public class ReservationService {
    private RoomRepository roomRepository;
    private GuestRepository guestRepository;
    private ReservationRepository reservationRepository;

    @Autowired
    public ReservationService(RoomRepository roomRepository, GuestRepository guestRepository, ReservationRepository reservationRepository) {
        this.roomRepository = roomRepository;
        this.guestRepository = guestRepository;
        this.reservationRepository = reservationRepository;
    }

My service class is shown above. Why can spring initialize an interface? Thank you

Anirudh
  • 2,286
  • 4
  • 38
  • 64
Ninja Dude
  • 1,332
  • 4
  • 27
  • 54
  • Probably you can find answer here http://stackoverflow.com/questions/33999879/spring-data-autowire-the-repository-interfaces-directly – Vijendra Kumar Kulhade Apr 09 '17 at 03:23
  • Possible duplicate of [How are Spring Data repositories actually implemented?](http://stackoverflow.com/questions/38509882/how-are-spring-data-repositories-actually-implemented) – dunni Apr 09 '17 at 08:58

1 Answers1

0

Spring is creating a proxy for the interface, the proxy delegates all calls to an already existing implementation. This post contains an excellent explanation

Community
  • 1
  • 1