docker run -itd -p 8000:80 docker.io/centos:latest /bin/bash
@Bean
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public TestBean getTestBean() {
return new TestBean();
}
ConfigurableBeanFactory.SCOPE_PROTOTYPE的值就是prototype
但是发现Autowire的时候,每一个请求用的还是同一个单例对象,这是因为没设置多例的代理模式的问题,改成如下配置就可以了:
@Bean
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE, proxyMode = ScopedProxyMode.TARGET_CLASS)
public TestBean getTestBean() {
return new TestBean();
}
原文:https://www.cnblogs.com/hlssz/p/14882470.html