Hackforge Academy

Category: java

Spring Boot, a Bean

Published on 26 May 2026

Explanation

In Spring Boot, a Bean is an object managed by the Spring IoC (Inversion of Control) container.

Code:

@Component
public class UserService {
}

Explanation

Singleton Bean: Only one instance is created for the entire application. This is the default bean scope in Spring.

Code:

@Component
@Scope("singleton")
public class UserService {
}

Explanation

Prototype Bean: A new object is created every time the bean is requested from the Spring container.

Code:

@Component
@Scope("prototype")
public class UserService {
}

Explanation

Request Bean: A new bean instance is created for every HTTP request in a web application.

Code:

@Component
@Scope(value =
 WebApplicationContext.SCOPE_REQUEST)
public class RequestBean {
}

Explanation

Beans can also be created using stereotypes and @Bean annotation inside configuration classes.

Code:

@Service
public class OrderService {
}

@Configuration
public class AppConfig {

    @Bean
    public UserService userService() {
        return new UserService();
    }
}

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community