工具類:
public class SpringConfigTool implements ApplicationContextAware {
private static ApplicationContext context = null;
private static SpringConfigTool stools = null;
public synchronized static SpringConfigTool init() {
if (stools == null) {
stools = new SpringConfigTool();
}
return stools;
}
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
context = applicationContext;
}
public synchronized static Object getBean(String beanName) {
return context.getBean(beanName);
}
}
調用demo:
private static ConfigItemService configItemService = null;
public static Properties getWordConfig() {
configItemService = (ConfigItemService) SpringConfigTool.getBean("configItemService");
}