Hands-On High Performance with Spring 5
上QQ阅读APP看书,第一时间看更新

Singleton versus prototype bean

In Spring, by default, all beans defined are singleton; however, we can change the default behavior and make our bean prototype. When the bean scope is set to prototype, the Spring IoC container creates a new bean instance of an object every time a bean is requested. Prototype beans incur a hit on performance during creation, so when a prototype bean uses resources, such as network and database connection, it should be avoided completely; alternatively, design the action carefully.