Java静态变量读取yaml配置

public final class ProxyProperties {
    private static boolean enable;
    private static String host;
    private static int port;
    private static String protocol;
    @Value("${proxy.enable:false}")
    private boolean proxyEnable;
    @Value("${proxy.host:127.0.0.1}")
    private String proxyHost;
    @Value("${proxy.port:80}")
    private int proxyPort;
    @Value("${proxy.protocol:http}")
    private String proxyProtocol;

    private ProxyProperties() {

    }


    public static boolean isEnable() {
        return enable;
    }

    public static String getHost() {
        return host;
    }

    public static int getPort() {
        return port;
    }

    public static String getProtocol() {
        return protocol;
    }

    @PostConstruct
    public void setBean() {
        setEnable(this.proxyEnable);
        setHost(this.proxyHost);
        setPort(this.proxyPort);
        setProtocol(this.proxyProtocol);
    }

    public static void setEnable(boolean enable) {
        ProxyProperties.enable = enable;
    }

    public static void setHost(String host) {
        ProxyProperties.host = host;
    }

    public static void setPort(int port) {
        ProxyProperties.port = port;
    }

    public static void setProtocol(String protocol) {
        ProxyProperties.protocol = protocol;
    }
}

 

posted @ 2022-06-28 10:01  苏黎世湖畔  阅读(770)  评论(0编辑  收藏  举报