What are the different types of Spring Bean scopes?

I-Hub Talent: The Best Full Stack Java Institute in Hyderabad

Looking for the best Full Stack Java institute in HyderabadI-Hub Talent is your go-to destination for expert-led training in Java, Spring Boot, Hibernate, Microservices, Frontend, and Backend Development. With an industry-focused curriculum and real-world projects, I-Hub Talent ensures students gain hands-on experience in Java programming, Angular, React, RESTful APIs, MySQL, NoSQL, and Cloud Deployment.

Our Full Stack Java course is designed for beginners and professionals, covering essential concepts like OOPs, Data Structures, Web Development, and Enterprise Application Development. At I-Hub Talent, you will receive personalized mentorship, interview preparation, and 100% placement assistance to kickstart your IT career.

Join I-Hub Talent’s Full Stack Java course in Hyderabad and build a strong foundation in Java-based technologies with top trainers. Take your career to new heights with practical learning, real-time projects, and career guidance.

In Spring Framework, bean scopes define the lifecycle and visibility of a bean within the Spring container. The most common bean scopes are:

  1. Singleton (Default)

    • Only one instance of the bean is created per Spring IoC container.

    • Shared and reused throughout the application context.

    • Ideal for stateless beans.

  2. Prototype

    • A new instance of the bean is created every time it is requested from the container.

    • Useful for stateful beans where each use requires a fresh object.

  3. Request (Web-aware scope)

    • One bean instance is created per HTTP request.

    • The bean is available only during the lifecycle of a single HTTP request.

  4. Session (Web-aware scope)

    • One bean instance is created per HTTP session.

    • The bean is tied to the lifecycle of a user session.

  5. Application (Web-aware scope)

    • One bean instance is created per ServletContext (application).

    • Shared across all requests and sessions in a web application.

  6. Websocket

    • One bean instance is created per WebSocket session.

Summary:

  • Singleton: Single shared instance (default)

  • Prototype: New instance on each request

  • Request: Per HTTP request

  • Session: Per HTTP session

  • Application: Per servlet context

  • Websocket: Per WebSocket session

Choosing the right scope is crucial for resource management and application behavior

Read More

Explain Dependency Injection in Spring.

What is the difference between Spring and Spring Boot?

Visit I-HUB TALENT Training institute in Hyderabad

Comments

Popular posts from this blog

What are Java's primitive data types?

Name three popular frontend technologies used with Java backend.

What is the Java Virtual Machine (JVM)?