What is @Configuration and @Bean?
Sometimes you need to use a third-party library class (e.g. RestTemplate or ObjectMapper) that you cannot edit to add @Component. You use a @Configuration class with @Bean methods!
AppConfig.java
@Configuration
public class AppConfig {
@Bean // Spring executes this method and stores the returned RestTemplate in the IoC container!
public RestTemplate restTemplate() {
return new RestTemplate();
}
}