Spring Request and Prototype Scope?

后端 未结 3 1344
忘了有多久
忘了有多久 2020-12-13 00:53

Below are the definitions of prototype and request scope in Spring.

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

request Sc

3条回答
  •  [愿得一人]
    2020-12-13 01:28

    Prototype scope creates a new instance every time getBean method is invoked on the ApplicationContext. Whereas for request scope, only one instance is created for an HttpRequest.

    So in an HttpRequest, if the getBean method is called twice on Application and there will be only one bean instantiated and reused, whereas the bean scoped to Prototype in that same single HttpRequest would get 2 different instances.

提交回复
热议问题