Building Microservices with Spring
上QQ阅读APP看书,第一时间看更新

Singleton design pattern implementation in the Spring Framework

The Spring Framework provides a Singleton scoped bean as a singleton pattern. It is similar to the singleton pattern, but it's not exactly the same as the Singleton pattern in Java. According to the Singleton pattern, a scoped bean in the Spring Framework means a single bean instance per container and per bean. If you define one bean for a particular class in a single Spring container, then the Spring container creates one and only one instance of the class defined by that bean definition.

Let's create a sample application of the singleton design pattern.