當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。