Singleton scope with annotation

@Scopes annotation is used to indicate the scope of a bean, either singleton, prototyperequest, session, or a few custom scopes.

To make the EmailService bean class a singleton, we need to annotate the class with @Scope and @ServiceSo, our EmailService class will look as follows: 

package com.packt.springbeanannotation;import org.springframework.context.annotation.Scope;import org.springframework.stereotype.Service;@Service@Scope("singleton")public class EmailService {    private String emailContent;  private String toAddress;    public EmailService() {    System.out.print(" \n Object of EmailService is Created !!! ");  }    public String getEmailContent() {    return emailContent;  }   public void setEmailContent(String ...

Get Java 9 Dependency Injection now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.