Spring @Scope Annotation Example
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjd_kQeK2F7QbzYFQ756AjDl01-0d2lygONdcBv9hLzo7B3K2EzfETEnXIxdTj-3eUULmgkckQlVKly2sVn_cjwjJ3GuB5I9A1T0gEpi6fpK4yT6ZDAgiuHoyjASe4YSKAx03XIv6Ar3Cp3aGA0IIeMuebCGowZoj506DPLKCaVBFe22WSeoGDpC-vZ8w/w400-h185/Untitled%20Diagram%20(1).drawio.png)
In this section we will learn about @Scope Annotation The scope of a bean defines the life cycle and visibility of that bean in the contexts in which it is used. A bean’s scope is set using the @Scope annotation. Singleton scope is the default scope in spring. Means, the Spring framework creates exactly one instance for each bean declared in the IoC container . The scopes supported out of the box are listed below: The last three scopes mentioned request , session , and globalSession are only available in a web-aware application. We use @Scope to define the scope of a @Component , @Service , and @Repository class or a @Bean definition. 1. Use @Scope to define the scope of a @Service. @Service @Scope (value = ConfigurableBeanFactory . SCOPE_PROTOTYPE ) //@Scope(value="prototype") public class EmailService implements MessageService { private String message ; @Override public String getMessage () { return message ; } @Override public v