org.springframework.context.ApplicationContextAware.setApplicationContext()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(65)

本文整理了Java中org.springframework.context.ApplicationContextAware.setApplicationContext()方法的一些代码示例,展示了ApplicationContextAware.setApplicationContext()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ApplicationContextAware.setApplicationContext()方法的具体详情如下:
包路径:org.springframework.context.ApplicationContextAware
类名称:ApplicationContextAware
方法名:setApplicationContext

ApplicationContextAware.setApplicationContext介绍

[英]Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

Invoked after population of normal bean properties but before an init callback such as org.springframework.beans.factory.InitializingBean#afterPropertiesSet()or a custom init-method. Invoked after ResourceLoaderAware#setResourceLoader, ApplicationEventPublisherAware#setApplicationEventPublisher and MessageSourceAware, if applicable.
[中]设置运行此对象的ApplicationContext。通常,此调用将用于初始化对象。
在填充普通bean属性之后但在初始化回调(如org)之前调用。springframework。豆。工厂初始化Bean#afterPropertieSet()或自定义初始化方法。在ResourceLoaderWare#setResourceLoader、ApplicationEventPublisherAware#SetApplicationEventPublisherAware和MessageSourceAware(如果适用)之后调用。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  for (ViewResolver viewResolver : this.viewResolvers) {
    if (viewResolver instanceof ApplicationContextAware) {
      ((ApplicationContextAware)viewResolver).setApplicationContext(applicationContext);
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public Object initializeBean(Object existingBean, String beanName) throws BeansException {
  if (existingBean instanceof ApplicationContextAware) {
    ((ApplicationContextAware) existingBean).setApplicationContext(StubWebApplicationContext.this);
  }
  return existingBean;
}

代码示例来源:origin: org.springframework/spring-webmvc

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  for (ViewResolver viewResolver : this.viewResolvers) {
    if (viewResolver instanceof ApplicationContextAware) {
      ((ApplicationContextAware)viewResolver).setApplicationContext(applicationContext);
    }
  }
}

代码示例来源:origin: spring-projects/spring-data-elasticsearch

@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
  if (elasticsearchConverter instanceof ApplicationContextAware) {
    ((ApplicationContextAware) elasticsearchConverter).setApplicationContext(context);
  }
}

代码示例来源:origin: geoserver/geoserver

@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
  if (factory instanceof ApplicationContextAware) {
    ((ApplicationContextAware) factory).setApplicationContext(context);
  }
}

代码示例来源:origin: spring-projects/spring-batch

/**
 * Add some factories to the set that will be used to load contexts and jobs.
 *
 * @param applicationContextFactory the {@link ApplicationContextFactory} values to use
 */
public void addApplicationContextFactory(ApplicationContextFactory applicationContextFactory) {
  if (applicationContextFactory instanceof ApplicationContextAware) {
    ((ApplicationContextAware) applicationContextFactory).setApplicationContext(applicationContext);
  }
  this.applicationContextFactories.add(applicationContextFactory);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  protected void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
    if (handlerExceptionResolvers == null) {
      return;
    }
    for (HandlerExceptionResolver resolver : handlerExceptionResolvers) {
      if (resolver instanceof ApplicationContextAware) {
        ApplicationContext applicationContext  = getApplicationContext();
        if (applicationContext != null) {
          ((ApplicationContextAware) resolver).setApplicationContext(applicationContext);
        }
      }
      if (resolver instanceof InitializingBean) {
        try {
          ((InitializingBean) resolver).afterPropertiesSet();
        }
        catch (Exception ex) {
          throw new IllegalStateException("Failure from afterPropertiesSet", ex);
        }
      }
      exceptionResolvers.add(resolver);
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

((ApplicationContextAware) this.jobFactory).setApplicationContext(this.applicationContext);

代码示例来源:origin: org.springframework/spring-context-support

((ApplicationContextAware) this.jobFactory).setApplicationContext(this.applicationContext);

代码示例来源:origin: org.springframework.boot/spring-boot

@Override
public void contextLoaded(ConfigurableApplicationContext context) {
  for (ApplicationListener<?> listener : this.application.getListeners()) {
    if (listener instanceof ApplicationContextAware) {
      ((ApplicationContextAware) listener).setApplicationContext(context);
    }
    context.addApplicationListener(listener);
  }
  this.initialMulticaster.multicastEvent(
      new ApplicationPreparedEvent(this.application, this.args, context));
}

代码示例来源:origin: spring-projects/spring-framework

private void invokeAwareInterfaces(Object bean) {
  if (bean instanceof Aware) {
    if (bean instanceof EnvironmentAware) {
      ((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());
    }
    if (bean instanceof EmbeddedValueResolverAware) {
      ((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(this.embeddedValueResolver);
    }
    if (bean instanceof ResourceLoaderAware) {
      ((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext);
    }
    if (bean instanceof ApplicationEventPublisherAware) {
      ((ApplicationEventPublisherAware) bean).setApplicationEventPublisher(this.applicationContext);
    }
    if (bean instanceof MessageSourceAware) {
      ((MessageSourceAware) bean).setMessageSource(this.applicationContext);
    }
    if (bean instanceof ApplicationContextAware) {
      ((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);
    }
  }
}

代码示例来源:origin: org.springframework/spring-context

private void invokeAwareInterfaces(Object bean) {
  if (bean instanceof Aware) {
    if (bean instanceof EnvironmentAware) {
      ((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());
    }
    if (bean instanceof EmbeddedValueResolverAware) {
      ((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(this.embeddedValueResolver);
    }
    if (bean instanceof ResourceLoaderAware) {
      ((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext);
    }
    if (bean instanceof ApplicationEventPublisherAware) {
      ((ApplicationEventPublisherAware) bean).setApplicationEventPublisher(this.applicationContext);
    }
    if (bean instanceof MessageSourceAware) {
      ((MessageSourceAware) bean).setMessageSource(this.applicationContext);
    }
    if (bean instanceof ApplicationContextAware) {
      ((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);
    }
  }
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void postProcessWhenApplicationContextAwareThenAwareInvoked() {
  this.spring.register(Config.class).autowire();
  ApplicationContextAware toPostProcess = mock(ApplicationContextAware.class);
  this.objectObjectPostProcessor.postProcess(toPostProcess);
  verify(toPostProcess).setApplicationContext(isNotNull());
}

代码示例来源:origin: org.apache.camel/camel-spring

protected void initBeanPostProcessor(SpringCamelContext context) {
  if (beanPostProcessor != null) {
    if (beanPostProcessor instanceof ApplicationContextAware) {
      ((ApplicationContextAware) beanPostProcessor).setApplicationContext(applicationContext);
    }
    if (beanPostProcessor instanceof CamelBeanPostProcessor) {
      ((CamelBeanPostProcessor) beanPostProcessor).setCamelContext(getContext());
    }
  }
}

代码示例来源:origin: gravitee-io/gravitee-gateway

((ApplicationContextAware) resourceInstance).setApplicationContext(applicationContext);

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-test

@Override
public Object initializeBean(Object existingBean, String beanName) throws BeansException {
  if (existingBean instanceof ApplicationContextAware) {
    ((ApplicationContextAware) existingBean).setApplicationContext(StubWebApplicationContext.this);
  }
  return existingBean;
}

代码示例来源:origin: org.springframework.batch.core/org.motechproject.org.springframework.batch.core

/**
 * Add some factories to the set that will be used to load contexts and jobs.
 *
 * @param applicationContextFactory the {@link ApplicationContextFactory} values to use
 */
public void addApplicationContextFactory(ApplicationContextFactory applicationContextFactory) {
  if (applicationContextFactory instanceof ApplicationContextAware) {
    ((ApplicationContextAware) applicationContextFactory).setApplicationContext(applicationContext);
  }
  this.applicationContextFactories.add(applicationContextFactory);
}

代码示例来源:origin: spring-projects/spring-integration

((ApplicationContextAware) this.handler).setApplicationContext(this.applicationContext);

代码示例来源:origin: spring-projects/spring-integration

((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);

代码示例来源:origin: micronaut-projects/micronaut-spring

private void wireAwareObjects(Object bean) {
  if (bean instanceof EnvironmentAware) {
    ((EnvironmentAware) bean).setEnvironment(environmentProvider.get());
  }
  if (bean instanceof BeanFactoryAware) {
    ((BeanFactoryAware) bean).setBeanFactory(beanFactoryProvider.get());
  }
  if (bean instanceof ApplicationContextAware) {
    ((ApplicationContextAware) bean).setApplicationContext(applicationContextProvider.get());
  }
}

相关文章

微信公众号

最新文章

更多

ApplicationContextAware类方法