Showing posts with the label @Scope

Spring @Scope Annotation Example

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