当前位置: 首页>>代码示例>>Java>>正文


Java ApplicationContextAware.setApplicationContext方法代码示例

本文整理汇总了Java中org.springframework.context.ApplicationContextAware.setApplicationContext方法的典型用法代码示例。如果您正苦于以下问题:Java ApplicationContextAware.setApplicationContext方法的具体用法?Java ApplicationContextAware.setApplicationContext怎么用?Java ApplicationContextAware.setApplicationContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.context.ApplicationContextAware的用法示例。


在下文中一共展示了ApplicationContextAware.setApplicationContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: inject

import org.springframework.context.ApplicationContextAware; //导入方法依赖的package包/类
public static void inject(ApplicationContext appCtx) {
    // Iterate through all registered tasks
    for (DiagnosticTask each : SelfDiagnose.getTasks()) {

     // First, custom tasks are a special case: we extract its task (this may be null), and then inject the Spring bean from the reference (if available:).
     // As for a custom task either its task or its reference is set (never both), 'each' will be null if we injected a Spring bean (for which the next step is not needed).

     if (each instanceof CustomDiagnosticTask) {
      CustomDiagnosticTask custom = (CustomDiagnosticTask) each;
      each = custom.getTask();
      injectTask(custom, appCtx);
     }

     // Then, if the task is (not null and) ApplicationContextAware, we inject the Spring context.

        if (each instanceof ApplicationContextAware) {
            ApplicationContextAware eachAware = (ApplicationContextAware) each;
            eachAware.setApplicationContext(appCtx);
        }
    }
}
 
开发者ID:emicklei,项目名称:selfdiagnose,代码行数:22,代码来源:SpringApplicationContextInjector.java

示例2: getBean

import org.springframework.context.ApplicationContextAware; //导入方法依赖的package包/类
/**
 * 从spring容器获取执行类型bean或者获取默认实现
 *
 * @param clz bean class 类型
 * @param <T>
 * @return bean
 */
private <T> T getBean(Class<T> clz) {
    T t = null;
    try {
        if (this.applicationContext != null) {
            t = this.applicationContext.getBean(clz);
        }
        if (t != null) {
            log.info("{}使用Spring注入:{}", clz.getSimpleName(), t.getClass());
        } else {
            t = DefaultRestyPassFactory.getDefaultBean(clz);
            log.info("{}使用默认配置:{}", clz.getSimpleName(), t.getClass());
            if (t == null) {
                throw new IllegalArgumentException("无法获取Bean:" + clz);
            }
            if (t instanceof ApplicationContextAware) {
                ApplicationContextAware contextAware = (ApplicationContextAware) serverContext;
                contextAware.setApplicationContext(this.applicationContext);
            }
        }

    } catch (BeansException ex) {
        t = DefaultRestyPassFactory.getDefaultBean(clz);
        log.info("{}使用默认配置:{}", clz.getSimpleName(), t.getClass());

    }
    return t;
}
 
开发者ID:darren-fu,项目名称:RestyPass,代码行数:35,代码来源:RestyProxyBeanFactory.java

示例3: setApplicationContext

import org.springframework.context.ApplicationContextAware; //导入方法依赖的package包/类
@Override
public void setApplicationContext( final ApplicationContext applicationContext ) throws BeansException
{
    if ( this.applicationBootstrap instanceof ApplicationContextAware )
    {
        // propagate application context to the application bootstrap
        ApplicationContextAware aware = (ApplicationContextAware) this.applicationBootstrap;
        aware.setApplicationContext( applicationContext );
    }
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:11,代码来源:PolygeneApplicationFactoryBean.java


注:本文中的org.springframework.context.ApplicationContextAware.setApplicationContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。