解释Spring支持的几种bean的作用域?

Spring框架支持以下五种bean的作用域:

singleton : bean在每个Spring ioc 容器中只有一个实例。 prototype :一个bean的定义可以有多个实例。 request :每次http请求都会创建一个bean,该作用域仅在基于web的Spring ApplicationContext情形下有效。 session :在一个HTTP Session中,一个bean定义对应一个实例。该作用域仅在基于web的Spring ApplicationContext情形下有效。 global-session :在一个全局的HTTP Session中,一个bean定义对应一个实例。该作用域仅在基于web的Spring ApplicationContext情形下有效。

缺省的Spring bean 的作用域是Singleton.

原文地址:https://www.cnblogs.com/programb/p/12851080.html