• springboot中引入zookeeper,生成 配置类


    1.application.properties

    zookeeper.address=@mvn.zookeeper.address@
    zookeeper.namespace=@mvn.zookeeper.namespace@
    

    2.pom.xml中多profile环境不同变量定义

    <properties>
            <maven.compiler.source>8</maven.compiler.source>
            <maven.compiler.target>8</maven.compiler.target>
    </properties>
    
    <profiles>
            <!-- 开发环境 -->
            <profile>
                <id>dev</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <properties>
                    <mvn.zookeeper.address>localhost:2181</mvn.zookeeper.address>
                    <mvn.zookeeper.namespace>fama_server</mvn.zookeeper.namespace>
                </properties>
            </profile>
            <profile>
                <id>prod</id>
                <properties>
                    <mvn.zookeeper.address>10.176.83.32:2181,10.176.83.33:2181,10.176.83.34:2181</mvn.zookeeper.address>
                    <mvn.zookeeper.namespace>fama_server</mvn.zookeeper.namespace>
                </properties>
            </profile>
    </profiles>
    

    3.配置类

    ZookeeperConfig.java

    @Component
    @PropertySource("classpath:application.properties")
    public class ZookeeperConfig {
    
        //zk connect config
        @Value("${zookeeper.address}")
        private String serverList;
    
        @Value("${zookeeper.retry.base.sleep:100}")
        private int baseSleepTimeMs;
    
        @Value("${zookeeper.retry.max.sleep:30000}")
        private int maxSleepMs;
    
        @Value("${zookeeper.retry.maxtime:10}")
        private int maxRetries;
    
        @Value("${zookeeper.session.timeout:60000}")
        private int sessionTimeoutMs;
    
        @Value("${zookeeper.connection.timeout:30000}")
        private int connectionTimeoutMs;
    
        @Value("${zookeeper.connection.digest: }")
        private String digest;
    
        @Value("${zookeeper.fama.root:/fama}")
        private String dsRoot;
    
        @Value("${zookeeper.max.wait.time:10000}")
        private int maxWaitTime;
    
        @Value("${zookeeper.namespace}")
        private String nameSpace;
    
        public String getServerList() {
            return serverList;
        }
    
        public void setServerList(String serverList) {
            this.serverList = serverList;
        }
    
        public int getBaseSleepTimeMs() {
            return baseSleepTimeMs;
        }
    
        public void setBaseSleepTimeMs(int baseSleepTimeMs) {
            this.baseSleepTimeMs = baseSleepTimeMs;
        }
    
        public int getMaxSleepMs() {
            return maxSleepMs;
        }
    
        public void setMaxSleepMs(int maxSleepMs) {
            this.maxSleepMs = maxSleepMs;
        }
    
        public int getMaxRetries() {
            return maxRetries;
        }
    
        public void setMaxRetries(int maxRetries) {
            this.maxRetries = maxRetries;
        }
    
        public int getSessionTimeoutMs() {
            return sessionTimeoutMs;
        }
    
        public void setSessionTimeoutMs(int sessionTimeoutMs) {
            this.sessionTimeoutMs = sessionTimeoutMs;
        }
    
        public int getConnectionTimeoutMs() {
            return connectionTimeoutMs;
        }
    
        public void setConnectionTimeoutMs(int connectionTimeoutMs) {
            this.connectionTimeoutMs = connectionTimeoutMs;
        }
    
        public String getDigest() {
            return digest;
        }
    
        public void setDigest(String digest) {
            this.digest = digest;
        }
    
        public String getDsRoot() {
            return dsRoot;
        }
    
        public void setDsRoot(String dsRoot) {
            this.dsRoot = dsRoot;
        }
    
        public int getMaxWaitTime() {
            return maxWaitTime;
        }
    
        public void setMaxWaitTime(int maxWaitTime) {
            this.maxWaitTime = maxWaitTime;
        }
    
        public String getNameSpace() {
            return nameSpace;
        }
    
        public void setNameSpace(String nameSpace) {
            this.nameSpace = nameSpace;
        }
    }
    
  • 相关阅读:
    博客园电子期刊2012年6月刊发布啦
    如何在博客园发博客时插入优酷视频
    上周热点回顾(7.167.22)
    “Coding changes the world” 博客园2012主题T恤专题上线
    [转]MySql查询缓存机制
    淘宝店铺开发 ShopSDK 1.x 及 TAE_SDK 2.0
    [转]NHibernate之旅系列文章导航
    MySQL 5.1参考手册 :: 7. 优化
    [转]Nant daily build实践
    [转]淘宝sdk——入门实战之footer.php制作
  • 原文地址:https://www.cnblogs.com/PythonOrg/p/14596462.html
Copyright © 2020-2023  润新知