SpringBoot项目配置disconf

说明: SpringBoot项目通过application.yml实现项目的配置, 配置文件如下:
server:
    port: 9090
    context-path: #/daily/

logging:
    level:
        tk.mybatis: TRACE

#启用shutdown
endpoints.shutdown.enabled: true
#禁用密码验证
endpoints.shutdown.sensitive: false

spring:
    datasource:
        name: sensitiveWords
        url: jdbc:mysql://10***.***.***/workplus
        username:*********
        password: ***.***.***
        # 使用druid数据源
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.jdbc.Driver
        filters: stat
        maxActive: 20
        initialSize: 1
        maxWait: 60000
        minIdle: 1
        timeBetweenEvictionRunsMillis: 60000
        minEvictableIdleTimeMillis: 300000
        validationQuery: select 'x'
        testWhileIdle: true
        testOnBorrow: false
        testOnReturn: false
        poolPreparedStatements: true
        maxOpenPreparedStatements: 20
    freemarker:
        cache: false
        request-context-attribute: request
    redis:
      host: 10.***.***.***
mybatis:
    type-aliases-package: com.alog.sensitivewords.model
    mapper-locations: classpath:mapper/*.xml

pagehelper:
    helperDialect: mysql
    reasonable: true
    supportMethodsArguments: true
    params: count=countSql
dubbo:
    registry:
        #address: 10.***.***.***:2181
        address: 127.0.0.1:2181
        port: 20892


通过disconf实现配置的在线化, 具体配置方式分为以下5个步骤
  1. 在pom文件中依赖
<dependency>
    <groupId>com.baidu.disconf</groupId>
    <artifactId>disconf-client</artifactId>
    <version>2.6.36</version>
</dependency>
  1. 增加disconf.properties文件
# \u662F\u5426\u4F7F\u7528\u8FDC\u7A0B\u914D\u7F6E\u6587\u4EF6
# true(\u9ED8\u8BA4)\u4F1A\u4ECE\u8FDC\u7A0B\u83B7\u53D6\u914D\u7F6E false\u5219\u76F4\u63A5\u83B7\u53D6\u672C\u5730\u914D\u7F6E
enable.remote.conf=true

#
# \u914D\u7F6E\u670D\u52A1\u5668\u7684 HOST,\u7528\u9017\u53F7\u5206\u9694  127.0.0.1:8000,127.0.0.1:8000
#
conf_server_host=disconf.dev.51juban.cn

# \u7248\u672C, \u8BF7\u91C7\u7528 X_X_X_X \u683C\u5F0F
version=1.0

# APP \u8BF7\u91C7\u7528 \u4EA7\u54C1\u7EBF_\u670D\u52A1\u540D \u683C\u5F0F
app= sensitive-word

# \u73AF\u5883 \u5F00\u53D1rd \u672C\u5730local  \u6D4B\u8BD5test
env=rd

# debug
debug=true
  1. 增加app-disconf.xml文件
<?xml version="1.0" encoding="UTF-8"?>
       xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "
       xmlns:aop=" http://www.springframework.org/schema/aop "
       xsi:schemaLocation=" http://www.springframework.org/schema/beans

    <aop:aspectj-autoproxy proxy-target-class="true"/>
    <bean id="disconfMgrBean" class="com.baidu.disconf.client.DisconfMgrBean"
          destroy-method="destroy">
        <property name="scanPackage" value="sensitive-server"/>
    </bean>

    <bean id="disconfMgrBean2" class="com.baidu.disconf.client.DisconfMgrBeanSecond"
          init-method="init" destroy-method="destroy">
    </bean>

    <bean id="configproperties_disconf"
          class="com.baidu.disconf.client.addons.properties.ReloadablePropertiesFactoryBean">
        <property name="locations">
            <list>
                <value>classpath*:application.yml</value>
            </list>
        </property>
    </bean>

    <bean id="propertyConfigurer"
          class="com.baidu.disconf.client.addons.properties.ReloadingPropertyPlaceholderConfigurer">
        <property name="ignoreResourceNotFound" value="true"/>
        <property name="ignoreUnresolvablePlaceholders" value="true"/>
        <property name="propertiesArray">
            <list>
                <ref bean="configproperties_disconf"/>
            </list>
        </property>
    </bean>
</beans>
  1. 在启动文件中引入app-disconf.xml的配置文件
package com.alog.sensitivewords;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;

@SpringBootApplication
@ImportResource({"classpath:dubbo-provider.xml", "classpath:app-disconf.xml"})
@MapperScan(basePackages = "com.alog.sensitivewords.mapper")
public class SensitiveWordsApplication {
    public static void main(String[] args) {
        SpringApplication.run(SensitiveWordsApplication.class, args);
    }
}
  1. 在线上的disconf新建APP, 然后新建配置文件, 然后倒入原来的application.yml文件即可.




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值