问题
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