@Configuration
public class AppConfig {
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}- @Component/@Service/@Repository — beans discovered via classpath scanning
- @Bean — beans declared explicitly inside a @Configuration class, useful for third-party classes you can't annotate
- By default beans are singleton-scoped — one instance per container