Spring Bean Scopes

前端 未结 9 1785
说谎
说谎 2020-11-29 18:25

Can someone explain what the scopes are in Spring beans I\'ve always just used \'prototype\' but are there other parameters I can put in place of that?

Example of wh

9条回答
  •  青春惊慌失措
    2020-11-29 18:56

    Detailed explanation for each scope can be found here in Spring bean scopes. Below is the summary

    Singleton - (Default) Scopes a single bean definition to a single object instance per Spring IoC container.

    prototype - Scopes a single bean definition to any number of object instances.

    request - Scopes a single bean definition to the lifecycle of a single HTTP request; that is, each HTTP request has its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext.

    session - Scopes a single bean definition to the lifecycle of an HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext.

    global session - Scopes a single bean definition to the lifecycle of a global HTTP Session. Typically only valid when used in a portlet context. Only valid in the context of a web-aware Spring ApplicationContext.

提交回复
热议问题