想去放牛

导航

 

bean的作用域由@scope注解来修改,该注解有五个不同的取值,分别是:singleton、prototype、request、session、global-session。

singleton,在每一个Spring容器中,一个Bean定义只有一个对象实例(默认为singleton)

prototype,允许Bean的定义可以被实例化任意次(每次调用都创建一个一个实例)
request,在一次HTTP请求中,每个Bean定义对应一个实例。该作用域仅在基于Web的Spring上下文(例如SpringMVC)中才有效
session,在一个HTTP Session中,每个Bean定义对应一个实例。该作用域仅在基于Web的Spring上下文(例如SpringMVC)中才有效
global-session,在一个全局HTTP
 Session中,每个Bean定义对应一个实例。该作用域仅在基于Web的Spring上下文(例如SpringMVC)中才有效

posted on 2022-04-20 17:55  想去放牛  阅读(109)  评论(0)    收藏  举报