In Spring, what is a 'bean'?
Options
- An object created and managed by the Spring container (Correct option)
- A kind of database used for caching Spring objects
- A Java keyword that marks any class as injectable
- A test file that checks the Spring configuration
Answer
An object that is created, assembled and managed by the Spring container
Why
The Spring documentation: a bean is an object that is instantiated, assembled and managed by a Spring IoC container.
Instead of writing new OrderService() everywhere, you let Spring create one and give it to the classes that need it (dependency injection).
Classes marked with @Component, @Service or @Repository become beans.
Remember
Bean = an object managed by Spring.