こんにちは、私はSpring 3を使用しています
私は使っています
applicationContext.getBeansOfType
現在のスコープで既にインスタンス化されている Bean のみを取得する可能性はありますか?
現在のリクエストでまだ使用されていない Bean をインスタンス化したくありません。
そうではないと思いますが、次のように書くことができます。
public static List<Object> getBeansInScope(Class<?> type, AbstractApplicationContext ctx, int scope) {
List<Object> beans = new ArrayList<Object>();
String[] names = ctx.getBeanNamesForType(type);
RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
for (String name : names) {
Object bean = attributes.getAttribute(name, scope);
if (bean != null)
beans.add(bean);
}
return beans;
}
これは、リクエスト スコープとセッション スコープでのみ機能します。