3
votes

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
any bean that you create using spring-context is managed by the spring container, you have an option to create a bean as prototype or singleton, not sure what you mean by model beans? - rahul pasricha
We usually create bean with setters and getters for example to save user information in db we are creating class called user it has setters and getters to save it in db using orm. - sridhar

1 Answers

3
votes

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.