Spring Beans
A bean is a regular object managed by Spring
The word bean sounds like a special kind of object, but there is no separate Bean
class in Spring. A bean is a regular Java object that has been created or registered in the container
and whose lifecycle is managed by Spring.
@Service
class PriceService {
int calculate(int basePrice) {
return basePrice;
}
}
If Spring discovers this class and registers it in the context,
an instance of PriceService becomes a bean.
If the same class is created manually with new PriceService(),
the resulting object does not become a bean by itself.
Why this distinction matters
The container knows about its beans: it can provide their dependencies, apply infrastructure processing to them, and take them into account while assembling other objects. An object created manually outside the container does not have that connection to Spring.
A bean has a type, a name, and a set of metadata that tell the container how to create and use it. Application code usually cares most about the type: Spring often uses it to choose a suitable dependency.