Files
contract-manager/server/src/main/java/com/ecep/contract/util/DefaultBeanContext.java
songqq 5b3ab3ed00 refactor(util): 重构BeanContext接口及相关实现
将ContextUtils重命名为BeanContext,并统一客户端和服务端的实现
添加DefaultBeanContext作为默认实现
优化Inventory同步任务逻辑,支持WebSocket远程调用
更新tasker_mapper.json添加新的任务映射
移除未使用的syncInventory方法
2025-10-12 22:39:32 +08:00

29 lines
805 B
Java

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<Class<?>, Object> cachedBeans = new HashMap<>();
public <T> T getBean(Class<T> requiredType) throws BeansException {
return getCachedBean(requiredType);
}
@SuppressWarnings("unchecked")
public <T> T getCachedBean(Class<T> requiredType) throws BeansException {
Object object = cachedBeans.get(requiredType);
if (object == null) {
object = SpringApp.getBean(requiredType);
cachedBeans.put(requiredType, object);
}
return (T) object;
}
}