2017-04-09 132 views
0
@Repository 
public interface RoomRepository extends CrudRepository<Room, Long>{ 
    Room findByNumber(String number); 
} 

我上面如何春季開機初始化庫

@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; 
    } 

我的服務類RoomRepository如上圖所示。爲什麼可以初始化一個接口?謝謝

+0

也許你可以找到答案這裏http://stackoverflow.com/questions/33999879/spring-data-autowire-the-repository-interfaces-directly –

+0

的可能的複製[如何是春數據倉庫實際執行?](http://stackoverflow.com/questions/38509882/how-are-spring-data-repositories-actually-實現) – dunni

回答

0

Spring正在爲接口創建一個代理,代理將所有調用委託給一個已經存在的實現。 This post包含一個很好的解釋