春天时豆模型会单身吗? [英] Are model beans singleton in spring?

查看:69
本文介绍了春天时豆模型会单身吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Spring中,用@Controller@Service@Repository@Component注释的类充当Spring Bean,并将由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).

在这里,模型bean没有任何构造型注释.

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

我的问题是模型bean是否为单例,即是否在Spring容器下.

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?

推荐答案

模型属性,例如.来自@ModelAttribute带注释的参数,不是bean.它们不受BeanFactory/ApplicationContext的管理.它们由DispatcherServlet的MVC堆栈创建并提供给您.没有并发问题(除非您创建一个),因为Servlet容器在单个线程中处理每个请求.

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.

这篇关于春天时豆模型会单身吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆