爬虫数据(mongo-209:55007)导入到Es
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
|||||||
|
package com.fangjia.job.common.util;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class SpringContextUtil implements ApplicationContextAware {
|
||||||
|
|
||||||
|
static SpringContextUtil Instance = new SpringContextUtil();
|
||||||
|
|
||||||
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
public SpringContextUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||||
|
if (applicationContext != null) {
|
||||||
|
Instance.applicationContext = applicationContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T getBean(Class<T> clzName) throws BeansException {
|
||||||
|
return Instance.applicationContext.getBean(clzName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static ApplicationContext getApplicationContext() {
|
||||||
|
return Instance.applicationContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getBean(String name, Class requiredType) {
|
||||||
|
return Instance.applicationContext.getBean(name, requiredType);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user