DIGITAL GURU
Java Roadmap Portfolio

Configuration Classes (@Configuration & @Bean)

How to register third-party beans using @Configuration and @Bean annotations.

Anuj Kumar Singh Written by Anuj Kumar Singh (Lead Engineer, 13+ yrs exp) 5 min read Verified Spring Boot 3+ Guide
3D Architecture Visualizer

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();
    }
}