Reputation: 1743
I'm new to Spring and I'm confused about something basic. Are the classes that are stereotyped (Service, Controller, Repository) treated as beans? I'm confused as to when you actually need to annotate/configure something as a bean and when you don't. Is it for the classes that aren't stereotyped?
Thanks!
Upvotes: 1
Views: 65
Reputation: 14398
From spring documentation:
In Spring, the objects that form the backbone of your application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. Otherwise, a bean is simply one of many objects in your application. Beans, and the dependencies among them, are reflected in the configuration metadata used by a container.
Service, Controller, Repository are managed by the Spring IoC container, so they are called beans. You annotate a class as @Serivice
, @Controller
, @Repository
, or more in general @Component
when you want spring to manage it: spring will manage the instance of annotated class in regard of the scope you select (not all these scope are always available):
Upvotes: 1