Scope of a Spring-Controller and its instance-variables

后端 未结 2 1728
北海茫月
北海茫月 2020-11-30 19:53

Are all controllers in Spring-MVC singletons and are shared among different sessions and requests?

If so, I assume that a class-variable like

public          


        
2条回答
  •  自闭症患者
    2020-11-30 20:06

    Yes, controllers in Spring-MVC are singletons. Between multiple requests your class variable get shared and might result into ambiguity. You can use @Scope("request") annotation above your controller to avoid such ambiguity.

提交回复
热议问题