1
我有以下代碼來在我的Spring應用程序中定義一個bean請求作用域bean。當請求範圍不可用時,請求作用域bean singleton
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
public MyBean myBean() {
return new MyBean(); // actually it is a more complex initialization
}
但有時我會想在脫機應用程序使用同一個bean那裏request
範圍不可,只有singleton
和prototype
是。
當request
不可用時,是否有辦法使這個相同的bean假定爲singleton
表單?
它非常好。我以前使用'@ Profile'。 –