public interface BeanFactory { String FACTORY_BEAN_PREFIX = "&"; /** * */ Object getBean(String name) throws BeansException; /** * */ <T> T getBean(String name, @Nullable Class<T> requiredType) throws BeansException; /** * */ Object getBean(String name, Object... args) throws BeansException; /** * */ <T> T getBean(Class<T> requiredType) throws BeansException; /** * */ <T> T getBean(Class<T> requiredType, Object... args) throws BeansException; /** * */ boolean containsBean(String name); /** * */ boolean isSingleton(String name) throws NoSuchBeanDefinitionException; /** * */ boolean isPrototype(String name) throws NoSuchBeanDefinitionException; /** * */ boolean isTypeMatch(String name, ResolvableType typeToMatch) throws NoSuchBeanDefinitionException; /** * */ boolean isTypeMatch(String name, @Nullable Class<?> typeToMatch) throws NoSuchBeanDefinitionException; /** * */ @Nullable Class<?> getType(String name) throws NoSuchBeanDefinitionException; /** * */ String[] getAliases(String name); }
-
getBean
重载了(overload)5个getBean方法:可分为1.按照name获取bean。2.按照type获取bean。
其中getBean(String name,Object... args)与getBean(Class<T> requiredType,Object... args)方法需要注意后面的参数Object是构造方法的参数。另外bean的scope(bean在IOC容器中的生命周期)需要配置为prototype。