Skip to content
Commitwise
Menu

Spring bean

Also called: Bean

An object that Spring creates, configures and hands to other objects, usually one shared instance per application.

Definition

Classes marked with @Component, @Service, @Repository or @RestController, and the results of @Bean methods, become beans. Spring creates them at startup, passes them to each other through constructors, and by default keeps exactly one instance of each, shared by every request and thread. That is why beans should not store data about a single request or user in their fields.

In practice

A QuoteController asks for a QuoteService in its constructor, and Spring passes in the single QuoteService bean.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.