本文整理匯總了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);
}
}
}
示例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;
}
示例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 );
}
}