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;
}
}

 

posted on 2014-03-14 16:00  有木有格子  阅读(208)  评论(0编辑  收藏  举报