本文整理汇总了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 );
}
}