sp启动后获取ApplicationContext 对象的方法

 


import java.util.Locale;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

@Service
public class SpringUtil implements ApplicationContextAware {
public static ApplicationContext appContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
appContext = applicationContext;
}
public static String getMessage(String key, Object... params) {
return getMessage(key, params, Locale.ENGLISH);
}
public static String getMessage(String key,Object[] params,Locale locale) {
return appContext.getMessage(key, params, locale);
}

http://bbs.22cg.com/forum-113-1.html
http://bbs.22cg.com/forum-111-1.html
tcc55.com
70ky.com
http://flash.22cg.com/baoshijieyulecheng/
http://flash.22cg.com/yingfengguojiyulecheng/


public static Object getBean(String serviceName){
Object obj = new Object();
try {
obj = SpringUtil.appContext.getBean(serviceName);
} catch (BeansException e) {
e.printStackTrace();
return null;
}
return obj;
}
}

sp启动后获取ApplicationContext 对象的方法,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。