springcloud18---springCloudConfig
2024-08-29 18:39:10
package com.itmuch.cloud; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
public class ConfigClientController { @Value("${profile}")
private String profile; //可以获取本地application.yml配置文件profile: ssss的值 @GetMapping("/profile")
public String getProfile() {
System.out.println(this.profile);
return this.profile;
}
}
package com.itmuch.cloud; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
application.yml
server:
port: 8081 # profile: ssss # 通过localhsot:8081/profile就可以访问到config server里面的配置,如果本地有profile属性就加载本地的profile属性
#
bootstrap.yml
# springcloud里面有一个启动上下文,用来加载远端的配置就是config server里面的配置
# 先加载bootstrap.yml加载config server里面的配置,然后去加载application.yml里面的配置
#
spring:
cloud:
config:
uri: http://localhost:8080 #config server的端口
profile: dev
label: master # 当configserver的后端存储是Git时,默认就是master
application:
name: foobar #本工程的名字,去config server的git仓库里面找foobar-dev.yml文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <parent>
<groupId>com.itmuch.cloud</groupId>
<artifactId>microservice-spring-cloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent> <artifactId>microservice-config-client</artifactId>
<packaging>jar</packaging> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencies>
<!-- config client依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<!-- springmvc依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies> </project>
package com.itmuch.cloud; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer; @SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
application.yml
server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://git.oschina.net/it-much/config-repo-51cto-video
username:
password: # git里面 foobar-dev.yml内容profile: profile-dev,给工程foobar使用的。
# git里面application.yml内容profile: profile-default,档foobar工程找不到foobar-dev.yml时候使用。
application.yml.bak1-基础使用方式
server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://git.oschina.net/it-much/config-repo-51cto-video
application.yml.bak2-通配符
server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://git.oschina.net/it-much/{application}
application.yml.bak3-模式匹配
server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://git.oschina.net/it-much/config-repo-51cto-video # 公用
repos:
simple: https://git.oschina.net/it-much/simple
special:
pattern: special*/dev*,special*/test*
uri: https://git.oschina.net/it-much/special
application.yml.bak4-搜索路径
server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://git.oschina.net/it-much/config-repo-51cto-video # 公用
search-paths:
- foo # foo路径
- bar # bar路径
application.yml.bak5-cloneOnStart
server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://git.oschina.net/it-much/config-repo-51cto-video # 公用
clone-on-start: true
repos:
simple: https://git.oschina.net/it-much/simple
special:
pattern: special*/dev*,special*/test*
uri: https://git.oschina.net/it-much/special
cloneOnStart: false
application.yml.bak6-账号密码
server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://git.oschina.net/it-much/config-repo-51cto-video
username:
password:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <parent>
<groupId>com.itmuch.cloud</groupId>
<artifactId>microservice-spring-cloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent> <artifactId>microservice-config-server</artifactId>
<packaging>jar</packaging> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencies>
<!-- config server依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency> </dependencies> </project>
最新文章
- 前端里神奇的BFC 原理剖析
- linux wget 命令用法详解(附实例说明)
- dp 46(再做一遍)
- Zabbix Step 1 : Install CentOS6.5 and Configration
- BackTrack5 (BT5)无线password破解教程WPA/WPA2-PSK无线password皴
- C#.NET的微信功能开发学习
- poj3070矩阵快速幂
- 广州图书馆借阅抓取——httpClient的使用
- RSA签名和验证数据
- JS获取页面复选框选中的值
- javascript 中的原型继承
- MySQL JDBC简单使用
- linux 安装svn客户端
- UVa 10562 Undraw the Trees(递归遍历)
- WDCP,LNMP安装PHP缓存加速扩展eAccelerator,xcache和memcached
- 【转】VSCode Web开发插件
- ACM数论之旅13---容斥原理(一切都是命运石之门的选择(=゚ω゚)ノ)
- Java将对象写入文件读出——序列化与反序列化
- 通过args数组获取数据
- 使用DataTables导出html表格