Grokking Spring Boot
0% completed
Constructor Injection
@Service public class BookingService { @Autowired private SeatRepository seats; @Autowired private PaymentClient payments; @Autowired private Notifier notifier; public String book(String seatLabel, String email) { ... } }
This version of BookingService has no constructor. Spring fills the three fields, and the running service books seats correctly. When we ran the booking project with this class, the application started with no errors.
A plain unit test of the same class failed at its first use of a dependency:
java.lang
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%