Card 06/ 07
All 7 cards
ExerciseDifficulty: Advanced1 min
Find the Wiring Bug
This application fails to start. Say why, and name the smallest fix.
interface ReceiptPrinter { void print(String text); }
@Component
class ThermalReceiptPrinter implements ReceiptPrinter { /* ... */ }
@Component
class EmailReceiptPrinter implements ReceiptPrinter { /* ... */ }
@Service
class CheckoutService {
CheckoutService(ReceiptPrinter printer) { /* ... */ }
}See the fix
Two beans implement ReceiptPrinter and nothing tells CheckoutService which one to take — the same shape as the NotificationSender gotcha. If thermal receipts are the default, add @Primary to ThermalReceiptPrinter; if CheckoutService specifically needs email, add @Qualifier("emailReceiptPrinter") to its constructor parameter instead.