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