package com.ecep.contract.util; import java.util.HashMap; import java.util.Map; import org.springframework.beans.BeansException; import com.ecep.contract.SpringApp; /** * 默认的Bean上下文实现类 */ public class DefaultBeanContext implements BeanContext { private Map, Object> cachedBeans = new HashMap<>(); public T getBean(Class requiredType) throws BeansException { return getCachedBean(requiredType); } @SuppressWarnings("unchecked") public T getCachedBean(Class requiredType) throws BeansException { Object object = cachedBeans.get(requiredType); if (object == null) { object = SpringApp.getBean(requiredType); cachedBeans.put(requiredType, object); } return (T) object; } }