统一配置中心-Web应用版
演示一个web中统一配置中心的使用,更多使用方式请参考dawdler-client-plug-config-center-consul.
1. 下载并运行
下载示例dawdler-tutorial.zip,版本为jdk1.8.
解压后,进入conf-center-consul-single-web目录中.
启动consul并配置dawdler-config.yml.
运行UserWebApplication.java的main方法.
@DawdlerBootApplication
public class UserWebApplication {
public static void main(String[] args) throws Throwable {
DawdlerWebApplication.run(UserWebApplication.class, args);
}
}
1.1 配置文件说明
FieldConfig注解相关配置参考dawdler-config-center-core.
consul安装及配置参考dawdler-config-center-consul-core.
1.2 consul中配置信息
例子中的配置信息如下:
创建节点 /testConfig
内容如下:
path: /test/config
创建节点 /paymentConfig
内容如下:
paymentUrl: https://api.payment.com/pay
paymentKey: 202303031
paymentSecret: test
1.3 通过jar包方式运行
通过运行
mvn clean package
获得 conf-center-consul-single-web-0.0.1-jdk1.8-SNAPSHOT-all.jar
运行
java -jar conf-center-consul-single-web-0.0.1-jdk1.8-SNAPSHOT-all.jar
1.4 验证
启动后访问 http://localhost:8085/user/getPath
、http://localhost:8085/user/getPaymentConfig
.