package com.fzzy.gateway.sc2023.api;
|
|
import org.springframework.beans.BeansException;
|
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.stereotype.Component;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
|
@Component
|
public class GatewayRemoteManager implements ApplicationContextAware {
|
|
public static Map<String, GatewayRemoteService> remoteMap1 = new HashMap<>();
|
|
@Override
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
Map<String, GatewayRemoteService> serviceMap = applicationContext.getBeansOfType(GatewayRemoteService.class);
|
|
for (String key : serviceMap.keySet()) {
|
remoteMap1.put(serviceMap.get(key).getProtocol(), serviceMap.get(key));
|
}
|
}
|
|
|
/**
|
* 根据实现协议获取当前实现方法
|
*
|
* @param protocol
|
* @return
|
*/
|
public GatewayRemoteService getRemoteService(String protocol) {
|
return remoteMap1.get(protocol);
|
}
|
|
}
|