package com.ots.project.tool; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; @Component public class AppUtil implements ApplicationContextAware { private static ApplicationContext applicationContext; public static T getObject(String id, Class T) { T bean = (T) applicationContext.getBean(id, T); return bean; } @Override public void setApplicationContext(ApplicationContext arg0) throws BeansException { applicationContext = arg0; } }