package com.ecep.contract.util; import java.util.HashMap; import org.springframework.beans.BeansException; import com.ecep.contract.SpringApp; public class BeanCacher { private HashMap, Object> cachedBeans = new HashMap<>(); @SuppressWarnings("unchecked") public T getBean(Class requiredType) throws BeansException { Object object = cachedBeans.get(requiredType); if (object == null) { object = SpringApp.getBean(requiredType); cachedBeans.put(requiredType, object); } return (T) object; } }