org.springframework.context.annotation

## 类 AnnotationConfigApplicationContext

- java.lang.Object
- - org.springframework.core.io.DefaultResourceLoader
  - - org.springframework.context.support.AbstractApplicationContext
    - - org.springframework.context.support.GenericApplicationContext
      - - org.springframework.context.annotation.AnnotationConfigApplicationContext

- 所有已实现的接口:
    Closeable, AutoCloseable, org.springframework.beans.factory.BeanFactory, org.springframework.beans.factory.HierarchicalBeanFactory, org.springframework.beans.factory.ListableBeanFactory, org.springframework.beans.factory.support.BeanDefinitionRegistry, AnnotationConfigRegistry, ApplicationContext, ApplicationEventPublisher, ConfigurableApplicationContext, Lifecycle, MessageSource, org.springframework.core.AliasRegistry, org.springframework.core.env.EnvironmentCapable, org.springframework.core.io.ResourceLoader, org.springframework.core.io.support.ResourcePatternResolver

      public class AnnotationConfigApplicationContext
      extends GenericApplicationContext
      implements AnnotationConfigRegistry

  Standalone application context, accepting annotated classes as input - in particular `@Configuration`-annotated classes, but also plain `@Component` types and JSR-330 compliant classes using `javax.inject` annotations. Allows for registering classes one by one using `register(Class...)` as well as for classpath scanning using `scan(String...)`.

  In case of multiple `@Configuration` classes, @`Bean` methods defined in later classes will override those defined in earlier classes. This can be leveraged to deliberately override certain bean definitions via an extra `@Configuration` class.

  See @`Configuration`'s javadoc for usage examples.

  从以下版本开始:
    3.0
  作者:
    Juergen Hoeller, Chris Beams
  另请参阅:
    `register(java.lang.Class<?>...)`, `scan(java.lang.String...)`, `AnnotatedBeanDefinitionReader`, `ClassPathBeanDefinitionScanner`, `GenericXmlApplicationContext`

- - ### 嵌套类概要

    - ### 从类继承的嵌套类/接口 org.springframework.core.io.DefaultResourceLoader

      `org.springframework.core.io.DefaultResourceLoader.ClassPathContextResource`

  - ### 字段概要

    - ### 从类继承的字段 org.springframework.context.support.AbstractApplicationContext

      `APPLICATION_EVENT_MULTICASTER_BEAN_NAME, LIFECYCLE_PROCESSOR_BEAN_NAME, logger, MESSAGE_SOURCE_BEAN_NAME`

    - ### 从接口继承的字段 org.springframework.context.ConfigurableApplicationContext

      `CONFIG_LOCATION_DELIMITERS, CONVERSION_SERVICE_BEAN_NAME, ENVIRONMENT_BEAN_NAME, LOAD_TIME_WEAVER_BEAN_NAME, SYSTEM_ENVIRONMENT_BEAN_NAME, SYSTEM_PROPERTIES_BEAN_NAME`

    - ### 从接口继承的字段 org.springframework.beans.factory.BeanFactory

      `FACTORY_BEAN_PREFIX`

    - ### 从接口继承的字段 org.springframework.core.io.support.ResourcePatternResolver

      `CLASSPATH_ALL_URL_PREFIX`

    - ### 从接口继承的字段 org.springframework.core.io.ResourceLoader

      `CLASSPATH_URL_PREFIX`

  - ### 构造器概要

    构造器
    构造器和说明
    `AnnotationConfigApplicationContext()` Create a new AnnotationConfigApplicationContext that needs to be populated through `register(java.lang.Class<?>...)` calls and then manually refreshed.
    `AnnotationConfigApplicationContext(Class<?>... annotatedClasses)` Create a new AnnotationConfigApplicationContext, deriving bean definitions from the given annotated classes and automatically refreshing the context.
    `AnnotationConfigApplicationContext(org.springframework.beans.factory.support.DefaultListableBeanFactory beanFactory)` Create a new AnnotationConfigApplicationContext with the given DefaultListableBeanFactory.
    `AnnotationConfigApplicationContext(String... basePackages)` Create a new AnnotationConfigApplicationContext, scanning for bean definitions in the given packages and automatically refreshing the context.

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `void` | `register(Class<?>... annotatedClasses)` Register one or more annotated classes to be processed.
    `<T> void` | `registerBean(Class<T> annotatedClass, Object... constructorArguments)` Register a bean from the given bean class, deriving its metadata from class-declared annotations, and optionally providing explicit constructor arguments for consideration in the autowiring process.
    `<T> void` | `registerBean(String beanName, Class<T> annotatedClass, Object... constructorArguments)` Register a bean from the given bean class, deriving its metadata from class-declared annotations, and optionally providing explicit constructor arguments for consideration in the autowiring process.
    `<T> void` | `registerBean(String beanName, Class<T> beanClass, Supplier<T> supplier, org.springframework.beans.factory.config.BeanDefinitionCustomizer... customizers)` Register a bean from the given bean class, using the given supplier for obtaining a new instance (typically declared as a lambda expression or method reference), optionally customizing its bean definition metadata (again typically declared as a lambda expression).
    `void` | `scan(String... basePackages)` Perform a scan within the specified base packages.
    `void` | `setBeanNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator beanNameGenerator)` Provide a custom `BeanNameGenerator` for use with `AnnotatedBeanDefinitionReader` and/or `ClassPathBeanDefinitionScanner`, if any.
    `void` | `setEnvironment(org.springframework.core.env.ConfigurableEnvironment environment)` Propagates the given custom `Environment` to the underlying `AnnotatedBeanDefinitionReader` and `ClassPathBeanDefinitionScanner`.
    `void` | `setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver)` Set the `ScopeMetadataResolver` to use for detected bean classes.

    - ### 从类继承的方法 org.springframework.context.support.GenericApplicationContext

      `cancelRefresh, closeBeanFactory, getAutowireCapableBeanFactory, getBeanDefinition, getBeanFactory, getClassLoader, getDefaultListableBeanFactory, getResource, getResources, isAlias, isBeanNameInUse, refreshBeanFactory, registerAlias, registerBean, registerBean, registerBean, registerBeanDefinition, removeAlias, removeBeanDefinition, setAllowBeanDefinitionOverriding, setAllowCircularReferences, setClassLoader, setParent, setResourceLoader`

    - ### 从类继承的方法 org.springframework.context.support.AbstractApplicationContext

      `addApplicationListener, addBeanFactoryPostProcessor, assertBeanFactoryActive, close, containsBean, containsBeanDefinition, containsLocalBean, createEnvironment, destroy, destroyBeans, doClose, findAnnotationOnBean, finishBeanFactoryInitialization, finishRefresh, getAliases, getApplicationListeners, getApplicationName, getBean, getBean, getBean, getBean, getBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanFactoryPostProcessors, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeansOfType, getBeansOfType, getBeansWithAnnotation, getDisplayName, getEnvironment, getId, getInternalParentBeanFactory, getInternalParentMessageSource, getMessage, getMessage, getMessage, getParent, getParentBeanFactory, getResourcePatternResolver, getStartupDate, getType, initApplicationEventMulticaster, initLifecycleProcessor, initMessageSource, initPropertySources, invokeBeanFactoryPostProcessors, isActive, isPrototype, isRunning, isSingleton, isTypeMatch, isTypeMatch, obtainFreshBeanFactory, onClose, onRefresh, postProcessBeanFactory, prepareBeanFactory, prepareRefresh, publishEvent, publishEvent, publishEvent, refresh, registerBeanPostProcessors, registerListeners, registerShutdownHook, resetCommonCaches, setDisplayName, setId, start, stop, toString`

    - ### 从类继承的方法 org.springframework.core.io.DefaultResourceLoader

      `addProtocolResolver, clearResourceCaches, getProtocolResolvers, getResourceByPath, getResourceCache`

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### 从接口继承的方法 org.springframework.beans.factory.support.BeanDefinitionRegistry

      `containsBeanDefinition, getBeanDefinitionCount, getBeanDefinitionNames`

    - ### 从接口继承的方法 org.springframework.core.AliasRegistry

      `getAliases`

    - ### 从接口继承的方法 org.springframework.context.ConfigurableApplicationContext

      `addProtocolResolver`

- - ### 构造器详细资料

    - #### AnnotationConfigApplicationContext

          public AnnotationConfigApplicationContext()

      Create a new AnnotationConfigApplicationContext that needs to be populated through `register(java.lang.Class<?>...)` calls and then manually refreshed.

    - #### AnnotationConfigApplicationContext

          public AnnotationConfigApplicationContext(org.springframework.beans.factory.support.DefaultListableBeanFactory beanFactory)

      Create a new AnnotationConfigApplicationContext with the given DefaultListableBeanFactory.
      参数:
        `beanFactory` - the DefaultListableBeanFactory instance to use for this context

    - #### AnnotationConfigApplicationContext

          public AnnotationConfigApplicationContext(Class<?>... annotatedClasses)

      Create a new AnnotationConfigApplicationContext, deriving bean definitions from the given annotated classes and automatically refreshing the context.
      参数:
        `annotatedClasses` - one or more annotated classes, e.g. `@Configuration` classes

    - #### AnnotationConfigApplicationContext

          public AnnotationConfigApplicationContext(String... basePackages)

      Create a new AnnotationConfigApplicationContext, scanning for bean definitions in the given packages and automatically refreshing the context.
      参数:
        `basePackages` - the packages to check for annotated classes

  - ### 方法详细资料

    - #### setEnvironment

          public void setEnvironment(org.springframework.core.env.ConfigurableEnvironment environment)

      Propagates the given custom `Environment` to the underlying `AnnotatedBeanDefinitionReader` and `ClassPathBeanDefinitionScanner`.
      指定者:
        `setEnvironment` 在接口中 `ConfigurableApplicationContext`
      覆盖:
        `setEnvironment` 在类中 `AbstractApplicationContext`
      参数:
        `environment` - the new environment
      另请参阅:
        `AbstractApplicationContext.createEnvironment()`

    - #### setBeanNameGenerator

          public void setBeanNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator beanNameGenerator)

      Provide a custom `BeanNameGenerator` for use with `AnnotatedBeanDefinitionReader` and/or `ClassPathBeanDefinitionScanner`, if any.

      Default is `AnnotationBeanNameGenerator`.

      Any call to this method must occur prior to calls to `register(Class...)` and/or `scan(String...)`.

      另请参阅:
        `AnnotatedBeanDefinitionReader.setBeanNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator)`, `ClassPathBeanDefinitionScanner.setBeanNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator)`

    - #### setScopeMetadataResolver

          public void setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver)

      Set the `ScopeMetadataResolver` to use for detected bean classes.

      The default is an `AnnotationScopeMetadataResolver`.

      Any call to this method must occur prior to calls to `register(Class...)` and/or `scan(String...)`.

    - #### register

          public void register(Class<?>... annotatedClasses)

      Register one or more annotated classes to be processed.

      Note that `AbstractApplicationContext.refresh()` must be called in order for the context to fully process the new classes.

      指定者:
        `register` 在接口中 `AnnotationConfigRegistry`
      参数:
        `annotatedClasses` - one or more annotated classes, e.g. `@Configuration` classes
      另请参阅:
        `scan(String...)`, `AbstractApplicationContext.refresh()`

    - #### scan

          public void scan(String... basePackages)

      Perform a scan within the specified base packages.

      Note that `AbstractApplicationContext.refresh()` must be called in order for the context to fully process the new classes.

      指定者:
        `scan` 在接口中 `AnnotationConfigRegistry`
      参数:
        `basePackages` - the packages to check for annotated classes
      另请参阅:
        `register(Class...)`, `AbstractApplicationContext.refresh()`

    - #### registerBean

          public <T> void registerBean(Class<T> annotatedClass,
                                       Object... constructorArguments)

      Register a bean from the given bean class, deriving its metadata from class-declared annotations, and optionally providing explicit constructor arguments for consideration in the autowiring process.

      The bean name will be generated according to annotated component rules.

      参数:
        `annotatedClass` - the class of the bean
        `constructorArguments` - argument values to be fed into Spring's constructor resolution algorithm, resolving either all arguments or just specific ones, with the rest to be resolved through regular autowiring (may be `null` or empty)
      从以下版本开始:
        5.0

    - #### registerBean

          public <T> void registerBean(@Nullable
                                       String beanName,
                                       Class<T> annotatedClass,
                                       Object... constructorArguments)

      Register a bean from the given bean class, deriving its metadata from class-declared annotations, and optionally providing explicit constructor arguments for consideration in the autowiring process.
      参数:
        `beanName` - the name of the bean (may be `null`)
        `annotatedClass` - the class of the bean
        `constructorArguments` - argument values to be fed into Spring's constructor resolution algorithm, resolving either all arguments or just specific ones, with the rest to be resolved through regular autowiring (may be `null` or empty)
      从以下版本开始:
        5.0

    - #### registerBean

          public <T> void registerBean(@Nullable
                                       String beanName,
                                       Class<T> beanClass,
                                       @Nullable
                                       Supplier<T> supplier,
                                       org.springframework.beans.factory.config.BeanDefinitionCustomizer... customizers)

      从类复制的说明: `GenericApplicationContext`
      Register a bean from the given bean class, using the given supplier for obtaining a new instance (typically declared as a lambda expression or method reference), optionally customizing its bean definition metadata (again typically declared as a lambda expression).

      This method can be overridden to adapt the registration mechanism for all `registerBean` methods (since they all delegate to this one).

      覆盖:
        `registerBean` 在类中 `GenericApplicationContext`
      参数:
        `beanName` - the name of the bean (may be `null`)
        `beanClass` - the class of the bean
        `supplier` - a callback for creating an instance of the bean (in case of `null`, resolving a public constructor to be autowired instead)
        `customizers` - one or more callbacks for customizing the factory's `BeanDefinition`, e.g. setting a lazy-init or primary flag