Card 02/ 07
All 7 cards
ExampleDifficulty: Intermediate1 min
One Constructor, No @Autowired Needed
RideService, rewritten with the one constructor it actually needs — and no @Autowired anywhere on it.
package rides;
interface RideRepository { String findById(String id); }
@Component
class InMemoryRideRepository implements RideRepository {
public String findById(String id) { return "Ride[" + id + "]"; }
}
@Service
class RideService {
private final RideRepository repository;
RideService(RideRepository repository) {
this.repository = repository;
}
String getRide(String id) { return repository.findById(id); }
}Ride[42]