Are model beans singleton in spring?

纵饮孤独 提交于 2019-12-10 21:38:37

问题


In spring the classes annotated with @Controller, @Service, @Repository, @Component act as Spring beans and will be instantiated by Spring container in singleton (Default scope).

Here the model beans are not annotated with any stereo type annotations.

My question here is whether the model beans are singleton or not i.e., if they come under Spring container.

If it is true then, how has the concurrency issue been handled?


回答1:


Model attributes, ex. from @ModelAttribute annotated parameters, are not beans. They are not managed by the BeanFactory / ApplicationContext. They are created by the DispatcherServlet's MVC stack and provided to you. There's no concurrency issue (unless you create one) because a Servlet container handles each request in a single thread.



来源:https://stackoverflow.com/questions/24411149/are-model-beans-singleton-in-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!