**自己公司使用的简单的SpringUtil,可以使用直接从Spring容器中获取对象.比较方便. 主要就是实现ApplicationContextAware ,学过Spring的都知道,Spring提供一些实现Aware对应的类,来获取对应的信息,比如,ApplicationContextAware ,会将ApplicationContext 注入进来;实现BeanFactoryAware接口的类能够获取到BeanFactory,实现了BeanNameAware的 类中能获取到自己在Spring容器中的属性…**注意: 这个工具类,所有实现对应Aware类也必须在spring容器中要不然,Spring不知道谁实现了对应Aware接口.简单的SpringUtil类如下:Component public class SpringContextUtil implements ApplicationContextAware { private static ApplicationContext context; //应用上下文环境 SuppressWarnings(static-access) Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.context applicationContext; } public static ApplicationContext getContext() { return context; } /** * 根据bean name 获取对象 * * param name * return */ public static T T getBean(String name) { return (T) context.getBean(name); } /** * 根据Class获取对象 * param clazz * param T * return * throws BeansException */ public static T T getBean(ClassT clazz) throws BeansException { return context.getBean(clazz); } }