深入了解Spring的@Scope注解中作用域代理proxyMode属性的实现

一.问题引入
代码如下:
@RestController
public class ConfigController {

@Autowired
private TestService testService;

@GetMapping("/testPrototype")
public String testPrototype() {
System.out.println(testService);
return testService.toString();
}
}
@Scope("prototype")
@Component
public class TestService {
}
当我们访问/testPrototype这个接口的时候,可以发现注入的TestService实例永远都只会有一个,如下图:

也就是说TestService在ConfigController中是以单例存在的,而我们想要的TestService的多例效果则是每次请求/testProt

深入了解Spring的@Scope注解中作用域代理proxyMode属性的实现最先出现在Python成神之路

版权声明:
作者:Zad
链接:https://www.techfm.club/p/14433.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>