【发布时间】:2016-03-12 06:03:39
【问题描述】:
我有以下代码在我的 Spring 应用程序中定义一个 bean 请求范围的 bean。
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
public MyBean myBean() {
return new MyBean(); // actually it is a more complex initialization
}
但有时我会想在request 范围不可用的离线应用程序中使用相同的bean,只有singleton 和prototype 可用。
当request 不可用时,有没有办法让同一个bean 呈现singleton 形式?
【问题讨论】: