Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 94ed32b commit 8745cecCopy full SHA for 8745cec
spring-boot/spring-boot单例说明.md
@@ -0,0 +1,5 @@
1
+### 一、默认情况下,`@Controller`、`@Service` 等都是单例的
2
+### 二、可使用 `@Scope(value = "prototype")` 将实例声明为多实例的,分以下情况
3
+1、只声明 Controller 不声明 Service,则所有 Controller 引用同一个 Service,因为 Service 在容器中是唯一的。
4
+2、只声明 Service 不声明 Controller,则同一个 Controller 中引用同一个 Service,多个 Controller 则引用不同的 Service。因为 Controller 是单例的,生成 Controller 实例时引入了 Service,下次再走这个 Controller 时依然是同一个 Service 变量。
5
+3、同时声明 Controller 和 Service,则每次都实例化新的 Service 实例。
0 commit comments