Repaso
EspaƱol
Spring, JPA & Java WebFoundationsSPR-40

In Spring, what is a 'bean'?

Options

  1. An object created and managed by the Spring container (Correct option)
  2. A kind of database used for caching Spring objects
  3. A Java keyword that marks any class as injectable
  4. 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.

Key terms

Practice this question in Repaso