✅ 1. What is a Java Bean (Simplified)
Think of a Java Bean like a container to hold data — for example: name, email, age, etc.
๐ฏ Rules for Java Bean:
-
It should have private variables
-
It should have public getters and setters
-
It should have a no-argument constructor
๐ง Example: Customer Java Bean
๐ก How do you use this Java Bean?
You can create an object and set/get values using the setters and getters:
✅ 2. What is a Spring Bean?
A Spring Bean is just a Java object that is created and managed by the Spring Framework.
Spring takes care of:
-
Creating the object
-
Injecting dependencies
-
Managing the lifecycle
๐งช Real Example with Spring Boot
๐ฆ Step 1: Create a simple class
๐ Step 2: Use this bean in another class
๐ Now, when you run the Spring Boot app and open http://localhost:8080/hello, it shows:
๐ง Summary
| Concept | Purpose | Example |
|---|---|---|
| Java Bean | Holds data (like a data model) | Customer with get/set |
| Spring Bean | Object created and managed by Spring Framework | HelloService, @Component |
No comments:
Post a Comment