站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 2.1.0 API 文档英文版

GenericBeanFactoryAccessor (Spring Framework API 2.1) - Spring Framework 2.1.0 API 文档英文版


The Spring Framework

org.springframework.beans.factory.generic
Class GenericBeanFactoryAccessor

java.lang.Object
  extended by org.springframework.beans.factory.generic.GenericBeanFactoryAccessor

public class GenericBeanFactoryAccessor
extends Object

Simple wrapper around a ListableBeanFactory that provides typed, generics-based access to key methods. This removes the need for casting in many cases and should increase compile-time type safety.

Provides a simple mechanism for accessing all beans with a particular Annotation.

Since:
2.0
Author:
Rob Harrop, Juergen Hoeller

Constructor Summary
GenericBeanFactoryAccessor(ListableBeanFactory beanFactory)
          Constructs a GenericBeanFactoryAccessor that wraps the supplied ListableBeanFactory.
 
Method Summary
<T> T
getBean(String name)
           
<T> T
getBean(String name, Class<T> requiredType)
           
 ListableBeanFactory getBeanFactory()
          Return the wrapped ListableBeanFactory.
<T> Map<String,T>
getBeansOfType(Class<T> type)
           
<T> Map<String,T>
getBeansOfType(Class<T> type, boolean includePrototypes, boolean allowEagerInit)
           
 Map<String,Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType)
          Find all beans whose Class has the supplied Annotation type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericBeanFactoryAccessor

public GenericBeanFactoryAccessor(ListableBeanFactory beanFactory)
Constructs a GenericBeanFactoryAccessor that wraps the supplied ListableBeanFactory.

Method Detail

getBeanFactory

public final ListableBeanFactory getBeanFactory()
Return the wrapped ListableBeanFactory.


getBean

public <T> T getBean(String name)
          throws BeansException
Throws:
BeansException
See Also:
BeanFactory.getBean(String)

getBean

public <T> T getBean(String name,
                     Class<T> requiredType)
          throws BeansException
Throws:
BeansException
See Also:
BeanFactory.getBean(String, Class)

getBeansOfType

public <T> Map<String,T> getBeansOfType(Class<T> type)
                             throws BeansException
Throws:
BeansException
See Also:
ListableBeanFactory.getBeansOfType(Class)

getBeansOfType

public <T> Map<String,T> getBeansOfType(Class<T> type,
                                        boolean includePrototypes,
                                        boolean allowEagerInit)
                             throws BeansException
Throws:
BeansException
See Also:
ListableBeanFactory.getBeansOfType(Class, boolean, boolean)

getBeansWithAnnotation

public Map<String,Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType)
Find all beans whose Class has the supplied Annotation type.

Parameters:
annotationType - the type of annotation to look for
Returns:
a Map with the matching beans, containing the bean names as keys and the corresponding bean instances as values

The Spring Framework

Copyright © 2002-2007 The Spring Framework.