Card 05/ 07
All 7 cards
ExampleDifficulty: Intermediate1 min
Wiring a Class You Don't Own
LegacyRideGateway ships inside a jar you depend on. You cannot add @Component to it — there is no source to edit — so scanning will never find it.
// no source available — cannot be annotated
class LegacyRideGateway {
LegacyRideGateway(String endpoint) { /* ... */ }
void call() { /* ... */ }
}
@Configuration
class GatewayConfig {
@Bean
LegacyRideGateway legacyRideGateway() {
return new LegacyRideGateway("https://legacy.internal/rides");
}
}calling legacy gateway at https://legacy.internal/ridesA @Bean method inside a @Configuration class does what scanning can't: it is ordinary Java, called by the container, and whatever it returns becomes a bean — regardless of what annotations that class carries, or doesn't.