jiazx0107@163.com
2023-10-24 f2cacfb5c8760d2b9b539821cc9e13054dbc1320
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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);
    }
 
}