我的服务地址(码云):https://gitee.com/xiechenxuyuan/SpringCouldConfig
如下:
从spring官网 :http://start.spring.io/创建一个简单的spring boot项目
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-config
org.springframework.cloud
spring-cloud-config-server
org.springframework.boot
spring-boot-starter-test
test
#服务端口
server.port=8091
#服务名称
spring.application.name=configServer
#服务注册中心 ,需要eureka 可以解开
#eureka.client.service-url.defaultZone=http://localhost:9761/eureka/
#服务的git仓库地址
spring.cloud.config.server.git.uri=https://gitee.com/xiechenxuyuan/SpringCouldConfig
@SpringBootApplication
@EnableConfigServer
//@EnableDiscoveryClient //eurekaClinet注解
public class SpringCloudConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudConfigServerApplication.class, args);
}
}
访问资源的形式如下:
The HTTP service has resources in the following form:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
{
"name": "application",
"profiles": [
"dev"
],
"label": null,
"version": "e0fa159ad38a0a064963b37a6abca0f7bfeb2fac",
"state": null,
"propertySources": [
{
"name": "https://gitee.com/xiechenxuyuan/SpringCouldConfig/application-dev.properties",
"source": {
"name": "shuaiqi",
"age": "22",
"version": "dev"
}
}
]
}
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-config
org.springframework.cloud
spring-cloud-config-server
org.springframework.boot
spring-boot-starter-test
test
#文件夹名
spring.application.name=application
# dev根据具体情况来修改
spring.cloud.config.profile=dev
spring.cloud.config.label=master
#eureka.client.service-url.defaultZone=http://localhost:9761/eureka/
spring.cloud.config.uri= http://localhost:8091/
#spring.cloud.config.discovery.enabled=true
#文件服务的服务名
spring.cloud.config.discovery.service-id=configServer
server.port=2008
@RestController
@SpringBootApplication
//@EnableDiscoveryClient // 表示这是一个Eureka客户端
public class SpringCloudConfigClientApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudConfigClientApplication.class, args);
}
@Value("${name}")
String name;
@Value("${version}")
String version;
@Value("${age}")
String age;
@RequestMapping("/")
public String home() {
return "name:" + name+",age:"+age+",version:"+version;
}
}
测试:输入localhost:2008