亲自动手搭建微服务框架和测试环境-10-配置中心

1实例

1)创建服务器

使用FileàNewàSpring Starter Project创建项目,按照向导选择config server

使用注解@EnableConfigServer,如下:

image.png


修改application.properties:

image.png

2)创建客户端

使用FileàNewàSpring Starter Project创建项目,按照向导选择config serverweb

创建控制器类,增加注解,如下:

image.png


增加配置文件bootstrap.properties:

image.png

修改application.properties:

image.png

3)启动和测试

Boot Dashboard中启动两个服务。

在浏览器中输入测试:

image.png

因为在git库中没有建立目录desktop/config,解决办法参见如下C问题,改为使用远程仓库。

 

修改远程仓库的a-bootiful-client.properties文件为:

image.png

测试结果:

image.png


image.png


这时需要进一步处理,在client项目中增加依赖:

image.png


重新启动client服务,然后在命令行中执行:

image.png


如果系统不识curl,则请安装curl工具。

再次测试client

image.png


测试成功。


4)问题:

A、无法启动client

image.png


原因是创建项目时忘记选择web,解决办法是增加对spring-boot-starter-web的依赖,以便启动tomcat

image.png


BNo such label: master

使用master分支,使用其他分支还需要特殊设置

CCannot clone or checkout repository: http://localhost:8000/scm/git/config

首先,修改服务器的application.properties:

image.png


然后,在本地master分支根目录下存放a-bootiful-client.properties文件。

最后,把master远程上传到git服务器,指令参见“3.14.3同步文件到远程仓库”。


DCannot load environment

Git状态不对,重启PC


猜你喜欢

转载自blog.51cto.com/5526964/2426402