Spring MVC 集成Disconf
1、Disconf:Distributed Configuration Management Platform(分布式配置管理平台),专注于各种「分布式系统配置管理」的「通用组件」和「通用平台」, 提供统一的「配置管理服务」
2、配置步骤:
1.maven中添加jar依赖:
<dependency>
<groupId>com.baidu.disconf</groupId>
<artifactId>disconf-client</artifactId>
</dependency>
2.spring配置文件配置(配置在springmvc的主配置文件中):
<!-- 使用disconf必须添加以下配置 -->
<bean id="disconfMgrBean" class="com.baidu.disconf.client.DisconfMgrBean" destroy-method="destroy">
<property name="scanPackage" value="com.sf" />
</bean>
<bean id="disconfMgrBean2" class="com.baidu.disconf.client.DisconfMgrBeanSecond" init-method="init" destroy-method="destroy">
</bean> <!-- 使用托管方式的disconf配置(无代码侵入, 配置更改会自动reload) -->
<bean id="configproperties_disconf"
class="com.baidu.disconf.client.addons.properties.ReloadablePropertiesFactoryBean">
<property name="locations">
<list>
<!--多个动态配置配置在这里-->
<value>classpath:redis.properties</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>
3.在resources文件夹下增加 disconf.properties 配置文件配置disconf:
#
# 配置服务器的 HOST,用逗号分隔 127.0.0.1:8000,127.0.0.1:8000
#
conf_server_host=XXXXXX # 版本, 请采用 X_X_X_X 格式
version=1_0_0_0 # APP 请采用 产品线_服务名 格式
app=XXXXX # 是否使用远程配置文件
# true(默认)会从远程获取配置 false则直接获取本地配置
enable.remote.conf=true # 环境
env=rd # debug
debug=true # 忽略哪些分布式配置,用逗号分隔
ignore= # 获取远程配置 重试次数,默认是3次
conf_server_url_retry_times=3 # 获取远程配置 重试时休眠时间,默认是5秒
conf_server_url_retry_sleep_seconds=1
4.添加properties配置文件:
redis.ip=127.0.0.1
redis1.port=8888
redis1.password=123456
5.使用spring的注解@Value来读取配置文件,并注入值
@Repository
public class RedisConfig { @Value("#{configproperties_disconf['redis.ip']}")
public String ip;
@Value("#{configproperties_disconf['redis.port']}")
public int port;
// getter & setter
}
6.通过注入类的属性使用proerties配置
通过上面配置已经将redis.properties的读取工作配置完成,在需要读取redis.properties的类中注入RedisConfig
@Autowired
RedisConfig redisConfig;
读取方式:redisConfig.getIp();
以上是使用spring集成disconf读取properties文件的配置过程,还需要将redisConfig配置文件上传到disconf的服务上,重启服务即可下载使用
Spring MVC 集成Disconf的更多相关文章
- spring boot 集成disconf
1.spring boot配置disconf需要在启动类上配置读取xml的入口注解:@ImportResource({"classpath:spring-disconf.xml"} ...
- Spring MVC集成slf4j-logback
转自: Spring MVC集成slf4j-logback 1. Spring MVC集成slf4j-log4j 关于slf4j和log4j的相关介绍和用法,网上有很多文章可供参考,但是关于logb ...
- spring mvc集成freemarker使用
freemarker作为视图技术出现的比velocity早,想当年struts风靡一时,freemarker作为视图层也风光了一把.但现在velocity作为后起之秀的轻量级模板引擎,更容易得到青睐. ...
- spring mvc集成velocity使用
目前流行的三大页面视图神器是:老牌大哥jsp.后起之秀freemarker和velocity.这里不详细比较这三者的优劣,总体来说,jsp是标配,但后面两个更严格的执行了视图与业务的分离,页面里是不允 ...
- spring mvc 集成freemarker模板
主要使用到的jar 文件:spring mvc +freemarker.jar 第一步:spring mvc 集成 freemarker <!-- 定义跳转的文件的前后缀 ,视图模式配置--&g ...
- Spring MVC集成Swagger
什么是Swagger? 大部分 Web 应用程序都支持 RESTful API,但不同于 SOAP API——REST API 依赖于 HTTP 方法,缺少与 Web 服务描述语言(Web Servi ...
- Spring MVC集成Log4j
以下示例显示如何使用Spring Web MVC框架集成LOG4J.首先使用Eclipse IDE,并按照以下步骤使用Spring Web Framework开发基于动态表单的Web应用程序: 创建一 ...
- Spring MVC集成Spring Data Reids和Spring Session实现Session共享
说明:Spring MVC中集成Spring Data Redis和Spring Session时版本是一个坑点,比如最新版本的Spring Data Redis已经不包含Jedis了,需要自行引入. ...
- Spring Boot与Spring MVC集成启动过程源码分析
开源项目推荐 Pepper Metrics是我与同事开发的一个开源工具(https://github.com/zrbcool/pepper-metrics),其通过收集jedis/mybatis/ht ...
随机推荐
- 炒鸡讨厌换python版本呀
https://www.cnblogs.com/yjlch1016/p/8641910.html 还是说,装个 Anaconda,你好我好大家好. https://blog.csdn.net/qq_3 ...
- 【bug记录】OS Lab3 踩坑记
OS Lab3 踩坑记 Lab3在之前Lab2的基础上,增加了进程建立.调度和中断异常处理.其中测试包括进程建立以及进程调度部分. 由于是第一次做bug记录,而且是调试完bug后再做的记录,所以导致记 ...
- 文件IO 相关的包:java.io文件——API
文件IO 相关的包:java.io文件——API 1.Java.io.File类的使用(1)两种路径绝对路径:相对于当前路径:当前为 “工程名”(2)File类创建,对象为一个文件/目录,可能存在或不 ...
- 添加ssl证书
ssl证书会使你的网站更加安全,防止isp在你的网站显示时添加广告,浏览网页时地址栏左边有一个绿色安全的图标,使用户感觉更加安全放心. 颁发ssl证书的机构很多,有收费的,也有免费的.当然对于自己的小 ...
- LeetCode - Backspace String Compare
Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...
- [双系统linux] ----安装完成后无法打开wifi
在安装了linux 双系统以后发现无法打开wifi和蓝牙. rfkill list all 0:ideapad_wlan: Wireless LANSoft blocked: noHard block ...
- xamarin android 文件选择
调出选择界面: Intent intent = new Intent(Intent.ActionGetContent); intent.AddCategory(Intent.CategoryOpena ...
- zookeeper启动报错处理记录
zookeeper启动时正常,查看状态时出错 处理,通过 ./zkServer.sh status 报错Error contacting service. It is probably not run ...
- C# .NET 按ASCII 从小到大排序
//C#的SortedDictionary<string,string>集合对key不是按照ascii码排序的因为他没有区分大小写,这就是个差别. 如果参数名中间有大写,小写,数字,Sor ...
- springMvc接收ajax数组参数,以及jquery复选框选中、反选、全选、全不选
一.复选框选中.反选.全选.全不选 html代码: <input type='checkbox' name='menuCheckBox' value='10' >苹果 <input ...