1.搭建项目环境
jdk1.8 + spring-boot.1.5.8 + spring-cloud.Dalston.SR4 + idea
2.搭建 config-service
创建一个项目(module)
按照提示一步一步创建完成项目。
创建后的目录:
我们先来配置application.properties(友情提示:官网推荐的文件名 bootstrap.yml,很多问题都是文件名称产生)
github 私人是需要收费的,我们一般采用公共的。所以 git 用户名,密码不需要配置。
再来看看ConfigServerApplication.java,我们加上@EnableConfigServer 注解就ok
我们通过 http://localhost:8888/foo/dev 访问下:
GitHub 地址:https://github.com/kevintanye/spring-cloud
主要的pom.xml 配置
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
3.搭建config-client
创建一个module
创建后的项目结构图
按我们熟悉的流程,我们先来配置bootstrap.properties
我们再来看看ConfigClientApplication.java
我们再来看看请求的结果:
ok。到这里我们的一个简单spring-cloud-config实例已经完成! 如果有其它问题,可以留言