类 GenericWebApplicationContext

java.lang.Object
cn.taketoday.core.io.DefaultResourceLoader
cn.taketoday.context.support.AbstractApplicationContext
cn.taketoday.context.support.GenericApplicationContext
cn.taketoday.web.servlet.support.GenericWebApplicationContext
所有已实现的接口:
cn.taketoday.beans.factory.BeanFactory, cn.taketoday.beans.factory.HierarchicalBeanFactory, cn.taketoday.beans.factory.support.BeanDefinitionRegistry, cn.taketoday.beans.factory.support.DependencyInjectorProvider, cn.taketoday.context.ApplicationContext, cn.taketoday.context.ApplicationEventPublisher, cn.taketoday.context.ConfigurableApplicationContext, cn.taketoday.context.Lifecycle, cn.taketoday.context.MessageSource, cn.taketoday.core.AliasRegistry, cn.taketoday.core.env.EnvironmentCapable, cn.taketoday.core.io.PatternResourceLoader, cn.taketoday.core.io.ResourceLoader, ConfigurableWebApplicationContext, WebApplicationContext, Closeable, AutoCloseable

public class GenericWebApplicationContext extends cn.taketoday.context.support.GenericApplicationContext implements ConfigurableWebApplicationContext
Subclass of GenericApplicationContext, suitable for web servlet environments.

Interprets resource paths as servlet context resources, i.e. as paths beneath the web application root. Absolute paths — for example, for files outside the web app root — can be accessed via file: URLs, as implemented by AbstractApplicationContext.

If you wish to register annotated component classes with a GenericWebApplicationContext, you can use an AnnotatedBeanDefinitionReader, as demonstrated in the following example. Component classes include in particular @Configuration classes but also plain @Component classes as well as JSR-330 compliant classes using jakarta.inject annotations.

 GenericWebApplicationContext context = new GenericWebApplicationContext();
 AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(context);
 reader.register(AppConfig.class, UserController.class, UserRepository.class);

If you intend to implement a WebApplicationContext that reads bean definitions from configuration files, consider deriving from AbstractRefreshableWebApplicationContext, reading the bean definitions in an implementation of the loadBeanDefinitions method.

从以下版本开始:
4.0 2022/2/20 21:03
作者:
Juergen Hoeller, Chris Beams, Sam Brannen, Harry Yang
  • 嵌套类概要

    从类继承的嵌套类/接口 cn.taketoday.core.io.DefaultResourceLoader

    cn.taketoday.core.io.DefaultResourceLoader.ClassPathContextResource

    从接口继承的嵌套类/接口 cn.taketoday.context.ApplicationContext

    cn.taketoday.context.ApplicationContext.State
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
     

    从类继承的字段 cn.taketoday.context.support.GenericApplicationContext

    beanFactory

    从类继承的字段 cn.taketoday.context.support.AbstractApplicationContext

    APPLICATION_EVENT_MULTICASTER_BEAN_NAME, LIFECYCLE_PROCESSOR_BEAN_NAME, log, MESSAGE_SOURCE_BEAN_NAME

    从接口继承的字段 cn.taketoday.context.ApplicationContext

    APPLICATION_NAME

    从接口继承的字段 cn.taketoday.beans.factory.BeanFactory

    FACTORY_BEAN_PREFIX

    从接口继承的字段 cn.taketoday.context.ConfigurableApplicationContext

    CONFIG_LOCATION_DELIMITERS, CONVERSION_SERVICE_BEAN_NAME, LOAD_TIME_WEAVER_BEAN_NAME, SHUTDOWN_HOOK_THREAD_NAME

    从接口继承的字段 cn.taketoday.web.servlet.ConfigurableWebApplicationContext

    SERVLET_CONFIG_BEAN_NAME

    从接口继承的字段 cn.taketoday.core.io.PatternResourceLoader

    CLASSPATH_ALL_URL_PREFIX

    从接口继承的字段 cn.taketoday.core.io.ResourceLoader

    CLASSPATH_URL_PREFIX
  • 构造器概要

    构造器
    构造器
    说明
    Create a new GenericWebApplicationContext.
    GenericWebApplicationContext(cn.taketoday.beans.factory.support.StandardBeanFactory beanFactory)
    Create a new GenericWebApplicationContext with the given StandardBeanFactory.
    GenericWebApplicationContext(cn.taketoday.beans.factory.support.StandardBeanFactory beanFactory, ServletContext servletContext)
    Create a new GenericWebApplicationContext with the given StandardBeanFactory and ServletContext.
    Create a new GenericWebApplicationContext for the given ServletContext.
  • 方法概要

    修饰符和类型
    方法
    说明
    protected cn.taketoday.core.env.ConfigurableEnvironment
    Create and return a new StandardServletEnvironment.
     
    Return the config locations for this web application context, or null if none specified.
    Return the namespace for this web application context, if any.
    protected cn.taketoday.core.io.PatternResourceLoader
    This implementation supports pattern matching in unexpanded WARs too.
    protected cn.taketoday.core.io.Resource
    This implementation supports file paths beneath the root of the ServletContext.
    Return the ServletConfig for this web application context, if any.
    Return the standard Servlet API ServletContext for this application.
    protected void
    protected void
    postProcessBeanFactory(cn.taketoday.beans.factory.config.ConfigurableBeanFactory beanFactory)
    Register request/session scopes, environment beans, a ServletContextAwareProcessor, etc.
    void
    setConfigLocation(String configLocation)
    Set the config locations for this web application context in init-param style, i.e. with distinct locations separated by commas, semicolons or whitespace.
    void
    setConfigLocations(String... configLocations)
    Set the config locations for this web application context.
    void
    setNamespace(String namespace)
    Set the namespace for this web application context, to be used for building a default context config location.
    void
    Set the ServletConfig for this web application context.
    void
    Set the ServletContext that this WebApplicationContext runs in.

    从类继承的方法 cn.taketoday.context.support.GenericApplicationContext

    cancelRefresh, closeBeanFactory, containsBeanDefinition, containsBeanDefinition, containsBeanDefinition, createBootstrapContext, getAliasList, getAutowireCapableBeanFactory, getBeanDefinition, getBeanDefinition, getBeanDefinitionCount, getBeanDefinitionNames, getBeanFactory, getClassLoader, getResource, getResources, isAlias, isAllowBeanDefinitionOverriding, isBeanDefinitionOverridable, isBeanNameInUse, refreshBeanFactory, refreshForAotProcessing, registerAlias, registerBean, registerBean, registerBean, registerBean, registerBean, registerBean, registerBeanDefinition, registerPrototype, registerPrototype, registerSingleton, registerSingleton, registerSingleton, registerSingleton, removeAlias, removeBeanDefinition, scan, setAllowBeanDefinitionOverriding, setAllowCircularReferences, setClassLoader, setParent, setResourceLoader

    从类继承的方法 cn.taketoday.context.support.AbstractApplicationContext

    addApplicationListener, addBeanFactoryPostProcessor, applyState, assertBeanFactoryActive, close, containsBean, containsLocalBean, destroyBeans, doClose, findAllAnnotationsOnBean, findAnnotationOnBean, findAnnotationOnBean, findSynthesizedAnnotation, finishBeanFactoryInitialization, finishRefresh, formatStartupDate, getAliases, getAnnotatedBeans, getApplicationEventMulticaster, getApplicationListeners, getBean, getBean, getBean, getBean, getBean, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanProvider, getBeanProvider, getBeanProvider, getBeanProvider, getBeans, getBeansOfType, getBeansOfType, getBeansOfType, getBeansWithAnnotation, getBeansWithAnnotation, getBootstrapContext, getDisplayName, getEnvironment, getExpressionEvaluator, getId, getInjector, getInternalParentBeanFactory, getInternalParentMessageSource, getLifecycleProcessor, getMessage, getMessage, getMessage, getParent, getParentBeanFactory, getStartupDate, getState, getType, getType, hasStarted, initApplicationEventMulticaster, initLifecycleProcessor, initMessageSource, invokeBeanFactoryPostProcessors, isActive, isPrototype, isRunning, isSingleton, isTypeMatch, isTypeMatch, obtainFreshBeanFactory, onClose, onRefresh, prepareBeanFactory, prepareRefresh, publishEvent, publishEvent, publishEvent, refresh, registerApplicationListeners, registerBeanPostProcessors, registerFrameworkComponents, registerShutdownHook, removeApplicationListener, resetCommonCaches, setBootstrapContext, setDisplayName, setEnvironment, setId, start, stop, toString, unwrapFactory

    从类继承的方法 cn.taketoday.core.io.DefaultResourceLoader

    addProtocolResolver, clearResourceCaches, getProtocolResolvers, getResourceCache

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

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

    从接口继承的方法 cn.taketoday.core.AliasRegistry

    getAliases

    从接口继承的方法 cn.taketoday.context.ApplicationContext

    getAutowireCapableBeanFactory, getDisplayName, getExpressionEvaluator, getId, getParent, getStartupDate, getState, hasStarted, unwrapFactory

    从接口继承的方法 cn.taketoday.context.ApplicationEventPublisher

    publishEvent, publishEvent

    从接口继承的方法 cn.taketoday.beans.factory.support.BeanDefinitionRegistry

    containsBeanDefinition

    从接口继承的方法 cn.taketoday.beans.factory.BeanFactory

    containsBean, containsBeanDefinition, findAllAnnotationsOnBean, findAnnotationOnBean, findAnnotationOnBean, findSynthesizedAnnotation, getAliases, getAnnotatedBeans, getBean, getBean, getBean, getBean, getBean, getBeanDefinition, getBeanDefinitionCount, getBeanDefinitionNames, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanProvider, getBeanProvider, getBeanProvider, getBeanProvider, getBeans, getBeansOfType, getBeansOfType, getBeansOfType, getBeansWithAnnotation, getBeansWithAnnotation, getType, getType, isPrototype, isSingleton, isTypeMatch, isTypeMatch, unwrap

    从接口继承的方法 cn.taketoday.context.ConfigurableApplicationContext

    addApplicationListener, addBeanFactoryPostProcessor, addProtocolResolver, close, getBeanFactory, getBootstrapContext, getEnvironment, isActive, refresh, registerShutdownHook, removeApplicationListener, setClassLoader, setEnvironment, setId, setParent

    从接口继承的方法 cn.taketoday.beans.factory.support.DependencyInjectorProvider

    getInjector

    从接口继承的方法 cn.taketoday.beans.factory.HierarchicalBeanFactory

    containsLocalBean, getParentBeanFactory

    从接口继承的方法 cn.taketoday.context.Lifecycle

    isRunning, start, stop

    从接口继承的方法 cn.taketoday.context.MessageSource

    getMessage, getMessage, getMessage

    从接口继承的方法 cn.taketoday.core.io.PatternResourceLoader

    getResources, getResourcesArray, scan

    从接口继承的方法 cn.taketoday.core.io.ResourceLoader

    getClassLoader, getResource
  • 字段详细资料

  • 构造器详细资料

    • GenericWebApplicationContext

      public GenericWebApplicationContext()
      Create a new GenericWebApplicationContext.
      另请参阅:
    • GenericWebApplicationContext

      public GenericWebApplicationContext(cn.taketoday.beans.factory.support.StandardBeanFactory beanFactory)
      Create a new GenericWebApplicationContext with the given StandardBeanFactory.
      参数:
      beanFactory - the StandardBeanFactory instance to use for this context
      另请参阅:
    • GenericWebApplicationContext

      public GenericWebApplicationContext(@Nullable ServletContext servletContext)
      Create a new GenericWebApplicationContext for the given ServletContext.
      参数:
      servletContext - the ServletContext to run in
      另请参阅:
      • GenericApplicationContext.registerBeanDefinition(java.lang.String, cn.taketoday.beans.factory.config.BeanDefinition)
      • AbstractApplicationContext.refresh()
    • GenericWebApplicationContext

      public GenericWebApplicationContext(cn.taketoday.beans.factory.support.StandardBeanFactory beanFactory, @Nullable ServletContext servletContext)
      Create a new GenericWebApplicationContext with the given StandardBeanFactory and ServletContext.
      参数:
      beanFactory - the StandardBeanFactory instance to use for this context
      servletContext - the ServletContext to run in
      另请参阅:
      • GenericApplicationContext.registerBeanDefinition(java.lang.String, cn.taketoday.beans.factory.config.BeanDefinition)
      • AbstractApplicationContext.refresh()
  • 方法详细资料

    • setServletContext

      public void setServletContext(@Nullable ServletContext servletContext)
      Set the ServletContext that this WebApplicationContext runs in.
      指定者:
      setServletContext 在接口中 ConfigurableWebApplicationContext
      另请参阅:
      • ConfigurableApplicationContext.refresh()
    • getServletContext

      @Nullable public ServletContext getServletContext()
      从接口复制的说明: WebApplicationContext
      Return the standard Servlet API ServletContext for this application.
      指定者:
      getServletContext 在接口中 WebApplicationContext
    • getApplicationName

      public String getApplicationName()
      指定者:
      getApplicationName 在接口中 cn.taketoday.context.ApplicationContext
      覆盖:
      getApplicationName 在类中 cn.taketoday.context.support.AbstractApplicationContext
    • createEnvironment

      protected cn.taketoday.core.env.ConfigurableEnvironment createEnvironment()
      Create and return a new StandardServletEnvironment.
      覆盖:
      createEnvironment 在类中 cn.taketoday.context.support.AbstractApplicationContext
    • getResourceByPath

      protected cn.taketoday.core.io.Resource getResourceByPath(String path)
      This implementation supports file paths beneath the root of the ServletContext.
      覆盖:
      getResourceByPath 在类中 cn.taketoday.core.io.DefaultResourceLoader
      另请参阅:
    • getPatternResourceLoader

      protected cn.taketoday.core.io.PatternResourceLoader getPatternResourceLoader()
      This implementation supports pattern matching in unexpanded WARs too.
      覆盖:
      getPatternResourceLoader 在类中 cn.taketoday.context.support.AbstractApplicationContext
      另请参阅:
    • postProcessBeanFactory

      protected void postProcessBeanFactory(cn.taketoday.beans.factory.config.ConfigurableBeanFactory beanFactory)
      Register request/session scopes, environment beans, a ServletContextAwareProcessor, etc.
      覆盖:
      postProcessBeanFactory 在类中 cn.taketoday.context.support.AbstractApplicationContext
    • initPropertySources

      protected void initPropertySources()

      Replace Servlet-related property sources.

      覆盖:
      initPropertySources 在类中 cn.taketoday.context.support.AbstractApplicationContext
    • setServletConfig

      public void setServletConfig(@Nullable ServletConfig servletConfig)
      从接口复制的说明: ConfigurableWebApplicationContext
      Set the ServletConfig for this web application context. Only called for a WebApplicationContext that belongs to a specific Servlet.
      指定者:
      setServletConfig 在接口中 ConfigurableWebApplicationContext
      另请参阅:
      • ConfigurableApplicationContext.refresh()
    • getServletConfig

      @Nullable public ServletConfig getServletConfig()
      从接口复制的说明: ConfigurableWebApplicationContext
      Return the ServletConfig for this web application context, if any.
      指定者:
      getServletConfig 在接口中 ConfigurableWebApplicationContext
    • setNamespace

      public void setNamespace(@Nullable String namespace)
      从接口复制的说明: ConfigurableWebApplicationContext
      Set the namespace for this web application context, to be used for building a default context config location. The root web application context does not have a namespace.
      指定者:
      setNamespace 在接口中 ConfigurableWebApplicationContext
    • getNamespace

      @Nullable public String getNamespace()
      从接口复制的说明: ConfigurableWebApplicationContext
      Return the namespace for this web application context, if any.
      指定者:
      getNamespace 在接口中 ConfigurableWebApplicationContext
    • setConfigLocation

      public void setConfigLocation(String configLocation)
      从接口复制的说明: ConfigurableWebApplicationContext
      Set the config locations for this web application context in init-param style, i.e. with distinct locations separated by commas, semicolons or whitespace.

      If not set, the implementation is supposed to use a default for the given namespace or the root web application context, as appropriate.

      指定者:
      setConfigLocation 在接口中 ConfigurableWebApplicationContext
    • setConfigLocations

      public void setConfigLocations(String... configLocations)
      从接口复制的说明: ConfigurableWebApplicationContext
      Set the config locations for this web application context.

      If not set, the implementation is supposed to use a default for the given namespace or the root web application context, as appropriate.

      指定者:
      setConfigLocations 在接口中 ConfigurableWebApplicationContext
    • getConfigLocations

      public String[] getConfigLocations()
      从接口复制的说明: ConfigurableWebApplicationContext
      Return the config locations for this web application context, or null if none specified.
      指定者:
      getConfigLocations 在接口中 ConfigurableWebApplicationContext