2021与蓝度共同重构项目,服务端
liuhaonan
2022-02-14 37041ac6ae6baa2996f447e495f6f5280113c4a2
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
38
39
40
41
42
package com.sandu.ximon.admin.utils;
 
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.sandu.ximon.admin.config.CommonConfig;
import org.springframework.stereotype.Component;
 
@Component("ClientUtils")
public class ClientUtils {
 
    public static ClientUtils getBean(){
        return (ClientUtils)SpringContextUtils.getBean("ClientUtils");
    }
 
    public DefaultAcsClient getClient() {
        DefaultAcsClient client = null;
 
        try {
            IClientProfile profile = DefaultProfile.getProfile(
                    CommonConfig.REGION_ID,
                    CommonConfig.ACCESS_KEY_ID,
                    CommonConfig.ACCESS_KEY_SECRET
            );
            DefaultProfile.addEndpoint(
                    CommonConfig.REGION_ID,
                    CommonConfig.REGION_ID,
                    CommonConfig.PRODUCT_CODE,
                    CommonConfig.DOMAIN
            );
            // 初始化client
            client = new DefaultAcsClient(profile);
 
        } catch (Exception e) {
            System.out.println("初始化client失败!exception:" + e.getMessage());
        }
 
        return client;
    }
 
 
}