提交 5ab0b464 编写于 作者: L laolunsi

add spring-cloud-config-demo

上级 17a678ad
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>config-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<artifactId>config-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>config-client</name>
<description>微服务A,从配置中心获取配置项</description>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.example.configclient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ConfigClientApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigClientApplication.class, args);
}
}
package com.example.configclient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author zhangfanghao
* @version 1.0
* @date 2019-12-27 22:41
*/
@RestController
@RequestMapping(value = "test")
public class TestAction {
/**
* 从配置中心读取配置项:msg
*/
@Value("${msg}")
private String msg;
@GetMapping(value = "hello")
public String hello() {
return "hello, " + msg;
}
}
server:
port: 8021
spring:
application:
name: config-demo
## 注意这里用 spring.config.name 是会导致启动报错
cloud:
config:
profile: dev
label: master
uri: http://localhost:8888/
package com.example.configclient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ConfigClientApplicationTests {
@Test
public void contextLoads() {
}
}
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>config-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<artifactId>config-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>config-server</name>
<description>配置中心</description>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.example.configserver;
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);
}
}
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: 'https://github.com/laolunsi/config-center-example'
search-paths: 'demo'
package com.example.configserver;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ConfigServerApplicationTests {
@Test
public void contextLoads() {
}
}
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.11.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>config-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>config-demo</name>
<description>微服务配置中心示例项目</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR4</spring-cloud.version>
</properties>
<modules>
<module>config-server</module>
<module>config-client</module>
</modules>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
# spring-boot-stack
:smile: 该仓库为Spring/SpringBoot/SpringCloud系列技术栈,涵盖实战教程+源码深入学习,一网打尽!
:smile: 该仓库为Spring/SpringBoot/SpringCloud系列技术栈,涵盖实战教程 + 源码深入学习,一网打尽!
目前还在持续更新中哒!欢迎大家与我一起学习进步鸭
目前还在持续更新中哦!欢迎大家与我一起学习进步
:tipping_hand_man: demo表示实战示例,study表示知识点的深入学习,还请注意哦
:tipping_hand_man: demo表示实战示例,study表示知识点的深入学习,请注意
如果您觉得该教程还算有所帮助,还请点个**star**支持一下!
......@@ -13,51 +13,60 @@
## SpringBoot
1. spring-boot-ssm-demo: [SpringBoot SSM 简单整合示例](http://www.eknown.cn/index.php/spring-boot/ssm-simple.html)
2. spring-boot-admin-demo: [SpringBoot 应用健康监控](http://www.eknown.cn/index.php/spring-boot/spring-boot-admin.html)
3. spring-boot-config-study: [SpringBoot 配置详解](http://www.eknown.cn/index.php/spring-boot/config.html)
4. spring-boot-swagger-demo: [SpringBoot 使用 Swagger 构建RestAPI 接口文档](http://www.eknown.cn/index.php/default/spring-boot-swagger.html)
5. spring-boot-exception-demo: [SpringBoot 统一异常处理](http://www.eknown.cn/index.php/spring-boot/exception-handler.html)
6. spring-boot-logback-demo: [SpringBoot 日志处理之Logback](http://www.eknown.cn/index.php/spring-boot/logback.html)
7. spring-boot-redis-demo: [SpringBoot 整合Redis](http://www.eknown.cn/index.php/spring-boot/spring-boot-redis.html)
8. spring-boot-mongo-demo: [SpringBoot 整合MongoDB](http://www.eknown.cn/index.php/spring-boot/spring-boot-mongodb.html)
9. spring-boot-params-time-demo: [SpringBoot 时间参数处理问题](http://www.eknown.cn/index.php/spring-boot/params-time.html)
10. spring-boot-mail-demo: [SpringBoot 邮件发送](http://www.eknown.cn/index.php/spring-boot/email.html)
11. spring-boot-application-study: [SpringBoot Application详解](http://www.eknown.cn/index.php/spring-boot/spring-boot-application.html)
12. sso-oauth2-demo: [SpringBoot OAuth2 单点登录示例](http://www.eknown.cn/index.php/spring-boot/oauth2-sso.html)
- [x] spring-boot-ssm-demo: [Spring Boot SSM 简单整合示例](http://www.eknown.cn/index.php/spring-boot/ssm-simple.html)
---
- [x] spring-boot-admin-demo: [Spring Boot 应用健康监控](http://www.eknown.cn/index.php/spring-boot/spring-boot-admin.html)
## SpringCloud
- [x] spring-boot-config-study: [Spring Boot 配置详解](http://www.eknown.cn/index.php/spring-boot/config.html)
13. spring-cloud-eureka-demo: [SpringCloud 服务注册与发现之Eureka](http://www.eknown.cn/index.php/springcloud/eureka.html)
14. spring-cloud-feign-demo: [SpringCloud 服务调用之 Feign](http://www.eknown.cn/index.php/springcloud/feign.html)
15. spring-cloud-consul-demo: [SpringCloud 服务注册中心之 Consul](http://www.eknown.cn/index.php/springcloud/consul.html)
16. spring-cloud-ribbon-demo: [SpringCloud 服务调用之 Ribbon](http://www.eknown.cn/index.php/springcloud/ribbon.html)
17. spring-cloud-hystrix-demo: [SpringCloud 熔断之 Hystrix](http://www.eknown.cn/index.php/springcloud/hystrix.html)
18. spring-cloud-ali-nacos-demo: [SpringCloud 阿里服务注册中心 Nacos](http://www.eknown.cn/index.php/spring-boot/nacos.html)
19. spring-cloud-admin-demo: [SpringCloud 应用健康监控](http://www.eknown.cn/index.php/springcloud/admin.html)
20. spring-cloud-config-demo: SpringCloud 配置中心
- [x] spring-boot-swagger-demo: [Spring Boot 使用 Swagger 构建 RestAPI 接口文档](http://www.eknown.cn/index.php/default/spring-boot-swagger.html)
未完待续...
- [x] spring-boot-exception-demo: [Spring Boot 统一异常处理](http://www.eknown.cn/index.php/spring-boot/exception-handler.html)
- [x] spring-boot-logback-demo: [Spring Boot 日志处理之 Logback](http://www.eknown.cn/index.php/spring-boot/logback.html)
- [x] spring-boot-redis-demo: [Spring Boot 整合 Redis](http://www.eknown.cn/index.php/spring-boot/spring-boot-redis.html)
- [x] spring-boot-mongo-demo: [Spring Boot 整合 MongoDB](http://www.eknown.cn/index.php/spring-boot/spring-boot-mongodb.html)
- [x] spring-boot-params-time-demo: [Spring Boot 时间参数处理问题](http://www.eknown.cn/index.php/spring-boot/params-time.html)
- [x] spring-boot-mail-demo: [SpringBoot 邮件发送](http://www.eknown.cn/index.php/spring-boot/email.html)
- [x] spring-boot-application-study: [Spring Boot Application 详解](http://www.eknown.cn/index.php/spring-boot/spring-boot-application.html)
- [x] sso-oauth2-demo: [Spring Boot OAuth2 单点登录示例](http://www.eknown.cn/index.php/spring-boot/oauth2-sso.html)
---
## 加入微信群
## SpringCloud
添加我的个人微信,备注 **加群** 即可。欢迎大家加入,一起分享学习和开发中遇到的问题!
- [x] spring-cloud-eureka-demo: [Spring Cloud 服务注册与发现之 Eureka](http://www.eknown.cn/index.php/springcloud/eureka.html)
- [x] spring-cloud-feign-demo: [Spring Cloud 服务调用之 Feign](http://www.eknown.cn/index.php/springcloud/feign.html)
- [x] spring-cloud-consul-demo: [Spring Cloud 服务注册中心之 Consul](http://www.eknown.cn/index.php/springcloud/consul.html)
- [x] spring-cloud-ribbon-demo: [Spring Cloud 服务调用之 Ribbon](http://www.eknown.cn/index.php/springcloud/ribbon.html)
- [x] spring-cloud-hystrix-demo: [Spring Cloud 熔断之 Hystrix](http://www.eknown.cn/index.php/springcloud/hystrix.html)
- [x] spring-cloud-ali-nacos-demo: [Spring Cloud 阿里服务注册中心 Nacos](http://www.eknown.cn/index.php/spring-boot/nacos.html)
- [x] spring-cloud-admin-demo: [Spring Cloud 应用健康监控](http://www.eknown.cn/index.php/springcloud/admin.html)
- [x] spring-cloud-config-demo:[ Spring Cloud 配置中心](https://mp.weixin.qq.com/s/QcIaGAYUvPBIqJM8oMbVvQ)
- [ ] spring-cloud-nacos-config-demo: Spring Cloud Nacos 配置中心
- [ ] spring-cloud-gateway: Spring Cloud Gateway
- [ ] spring-cloud-template: Spring Cloud 模板项目
![file](http://zfh-public-blog.oss-cn-beijing.aliyuncs.com/image-1578375120717.png)
未完待续...
## 关注公众号
---
## 个人公众号
关注公众号:猿生物语。每周分享**干货**技术文章。
可免费获取云盘学习资料。
作者菌有一个小小的公众号,分享 Java 编程技术,以及工作生活中的一些感悟。欢迎加入!
如果大家想要实时关注我的文章和分享动态的话,可以关注一下!
微信搜索 **猿生物语** or **JavaApes** ,或扫码。
![file](http://zfh-public-blog.oss-cn-beijing.aliyuncs.com/image-1578371742220.png)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册