Java Developers
Group for Java developers and programmers. Ask questions and get answers related to Java programming
270 Members
Join this group to post and comment.
Soubhik Maji
Soubhik Maji
Computer Science
05 Feb 2019

Basic Bean scopes and Annotations in Spring

Insert your code here 

Basic bean scopes 

1.Singleton ...only one per spring container   (application context)..

2. Prototype bean created for every request(getbean) or reference (every reference of an object that is dependent on this object )


@component-creates a bean represents the whole ,where parts are put in dependency injection .

@service- creates a bean , letting spring known it is a service layer class, i.e. it is going to give us a additional benefit apart from creating/registering a bean 

@repository- You are telling spring this bean is dao layer bean i.e. you are telling spring what role this bean does ,also it creates/registers the bean .

@controllers-  Creates the bean and gives us/spring a additional benefit of knowing the role of the bean I.e. it is a bean which acts as a controller in the MVC architecture .

The above annotations are used above class declarations or definations and you need to specify a configuration in XML for spring to tell that it needs to scan the bean from both created from reading XML and also from Annotations .

The annotations also acts as for readability of code for the fellow programmers .