潘志宝
2025-02-28 9882627244a4758df2025721ab13e33a035a5088
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
43
44
45
46
47
48
package com.iailab.sdk.auth.config;
 
import org.springframework.context.annotation.Configuration;
 
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
 
/**
 * SDK配置文件
 */
@Configuration
public class SdkConfiguration {
 
    private String baseUrl;
 
    public String getTenantId() {
        return tenantId;
    }
 
    private String tenantId;
 
    public static SdkConfiguration load() {
        SdkConfiguration config = new SdkConfiguration();
 
        try(InputStream is = SdkConfiguration.class.getResourceAsStream("/application.yaml")) {
            Properties props = new Properties();
            props.load(is);
            config.baseUrl = props.getProperty("base-url");
            config.tenantId = props.getProperty("tenant-id");
        } catch (IOException e) {
            // 处理异常或使用默认值
        }
 
        if(config.baseUrl == null) {
            throw new IllegalStateException("BaseUrl must be configured");
        }
        if(config.tenantId  == null) {
            throw new IllegalStateException("TenantId must be configured");
        }
 
        return config;
    }
 
    public String getBaseUrl() {
        return baseUrl;
    }
}