git init
|
spring:
profiles:
active:
- dev
---
spring:
profiles: dev
application:
name: springCloud-dev
---
spring:
profiles: beta
application:
name: springCloud-beta
|
#将更新添加到本地暂存仓库
git add .
#将本地暂存仓库的文件提交到本地库
git commit -m "add application.yml file"
#同步推送到服务器端
git push origin master
|
|
server:
port: 8300
spring:
application:
name: springCloud-config #配置中心的应用名称
cloud:
config:
server:
git:
uri: git@gitServerIP:springCloudConfig.git #远程git的地址
username: yourname #远程git认证的账号
password: yourpass #远程git认证的密码 (此处在我的电脑上已经进行过ssh配置,所有我并未设置)
|
@SpringBootApplication
@EnableConfigServer
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
|
1./{application}/{profile}[/{lable}]
2./{application}-{profile}.yml
3./{lable}/{application}-{profile}.yml
|
|
spring:
profiles:
active:
- dev
---
spring:
profiles: dev
application:
name: springCloud-dev
---
spring:
profiles: beta
application:
name: springCloud-beta
|
server:
port: 8888
spring:
application:
name: springCloud-config
profiles:
active:
- native
|
cloud:
config:
server:
native:
search-locations: file:./config,classpath:configg
|
cloud:
config:
server:
native:
search-locations:
- file:./config
- classpath:configg
|
@SpringBootApplication
@EnableConfigServer
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
|
|
spring:
application:
name: springCloud-configClient-service
|
spring:
cloud:
config:
name: springCloud-configClient #读取配置文件的文件名字
profile: beta #读取配置文件的段
uri: http://localhost:8888/ #配置中心的地址,此处如果是负载均衡,需要用“,”分隔
#username: 如果配置中心设置了安全认证,在此处设置认证账号
#password: 如果配置中心设置了安全认证,在此处设置认证密码
|
@RestController
public class UltraServiceController {
@Value("${spring.application.name}")
private String application_name ;
@RequestMapping("/get")
public Object getSessionId() {
return "获取到的引用名称:"+application_name;
}
}
|
@SpringBootApplication
public class UtralServiceApplication {
public static void main(String[] args) {
SpringApplication.run(UtralServiceApplication.class, args);
}
}
|