Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/e-1spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@ AOP(Aspect-Oriented Programming:面向切面编程)能够将那些与业务无

#### Spring 中的 bean 的作用域有哪些?

- singleton : 唯一 bean 实例,Spring 中的 bean 默认都是单例的
- prototype : 每次请求都会创建一个新的 bean 实例
- singleton : 在spring IoC容器仅存在一个Bean实例,Bean以单例方式存在,默认值
- prototype : 每次从容器中调用Bean时,都返回一个新的实例,即每次调用getBean()时,相当于执行newXxxBean()
- request : 每一次HTTP请求都会产生一个新的bean,该bean仅在当前HTTP request内有效。
- session : 每一次HTTP请求都会产生一个新的 bean,该bean仅在当前 HTTP session 内有效
- session : 同一个HTTP Session共享一个Bean,不同Session使用不同的Bean
- global-session: 全局session作用域,仅仅在基于portlet的web应用中才有意义,Spring5已经没有了。Portlet是能够生成语义代码(例如:HTML)片段的小型Java Web插件。它们基于portlet容器,可以像servlet一样处理HTTP请求。但是,与 servlet 不同,每个 portlet 都有不同的会话

参考自[W3Cschool-bean作用域](https://www.w3cschool.cn/wkspring/nukv1ice.html)

#### Spring 中的单例 bean 的线程安全问题了解吗?

大部分时候我们并没有在系统中使用多线程,所以很少有人会关注这个问题。单例 bean 存在线程问题,主要是因为当多个线程操作同一个对象的时候,对这个对象的非静态成员变量的写操作会存在线程安全问题。
Expand Down