Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are model beans singleton in spring?

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?

like image 727
sridhar Avatar asked Jun 15 '26 03:06

sridhar


1 Answers

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.

like image 108
Sotirios Delimanolis Avatar answered Jun 16 '26 16:06

Sotirios Delimanolis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!