forked from yudaocode/SpringBoot-Labs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
YunaiV
committed
Apr 9, 2020
1 parent
7348e04
commit 2a1ab5f
Showing
10 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
labx-19/labx-19-sc-config-server-git-auto-refresh-by-bus/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>labx-12</artifactId> | ||
<groupId>cn.iocoder.springboot.labs</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>labx-19-sc-config-server-git-auto-refresh-by-bus</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<spring.boot.version>2.2.4.RELEASE</spring.boot.version> | ||
<spring.cloud.version>Hoxton.SR1</spring.cloud.version> | ||
</properties> | ||
|
||
<!-- | ||
引入 Spring Boot、Spring Cloud、Spring Cloud Alibaba 三者 BOM 文件,进行依赖版本的管理,防止不兼容。 | ||
在 https://dwz.cn/mcLIfNKt 文章中,Spring Cloud Alibaba 开发团队推荐了三者的依赖关系 | ||
--> | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>${spring.boot.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<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> | ||
|
||
<dependencies> | ||
<!-- 引入 SpringMVC 相关依赖,并实现对其的自动配置 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<!-- 引入 Spring Cloud Stream Kafka 相关依赖,将 Kafka 作为消息队列,并实现对其的自动配置 --> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-config-server</artifactId> | ||
</dependency> | ||
|
||
<!-- 引入基于 Kafka 的 Spring Cloud Bus 的实现的依赖,并实现对其的自动配置 --> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-bus-kafka</artifactId> | ||
</dependency> | ||
|
||
<!-- 引入 Spring Cloud Config Monitor 依赖,提供 `/monitor` 接口,用于刷新配置 --> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-config-monitor</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
15 changes: 15 additions & 0 deletions
15
...src/main/java/cn/iocoder/springcloud/labx19/configserverdemo/ConfigServerApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cn.iocoder.springcloud.labx19.configserverdemo; | ||
|
||
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); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
labx-19/labx-19-sc-config-server-git-auto-refresh-by-bus/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
server: | ||
port: 8888 | ||
|
||
spring: | ||
application: | ||
name: demo-config-server | ||
|
||
profiles: | ||
active: git # 使用的 Spring Cloud Config Server 的存储器方案 | ||
# Spring Cloud Config 相关配置项 | ||
cloud: | ||
config: | ||
server: | ||
# Spring Cloud Config Server 的 Git 存储器的配置项,对应 MultipleJGitEnvironmentProperties 类 | ||
git: | ||
uri: https://github.com/YunaiV/demo-config-server.git # Git 仓库地址 | ||
search-paths: / # 读取文件的根地址 | ||
default-label: master # 使用的默认分支,默认为 master | ||
# username: ${CODING_USERNAME} # 账号 | ||
# password: ${CODING_PASSWORD} # 密码 | ||
|
||
# Kafka 配置项,对应 KafkaProperties 配置类 | ||
kafka: | ||
bootstrap-servers: 127.0.0.1:9092 # 指定 Kafka Broker 地址,可以设置多个,以逗号分隔 |
64 changes: 64 additions & 0 deletions
64
labx-19/labx-19-sc-config-user-application-auto-refresh-by-bus/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>labx-12</artifactId> | ||
<groupId>cn.iocoder.springboot.labs</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>labx-19-sc-config-user-application-auto-refresh-by-bus</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<spring.boot.version>2.2.4.RELEASE</spring.boot.version> | ||
<spring.cloud.version>Hoxton.SR1</spring.cloud.version> | ||
</properties> | ||
|
||
<!-- | ||
引入 Spring Boot、Spring Cloud、Spring Cloud Alibaba 三者 BOM 文件,进行依赖版本的管理,防止不兼容。 | ||
在 https://dwz.cn/mcLIfNKt 文章中,Spring Cloud Alibaba 开发团队推荐了三者的依赖关系 | ||
--> | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>${spring.boot.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<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> | ||
|
||
<dependencies> | ||
<!-- 引入 SpringMVC 相关依赖,并实现对其的自动配置 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<!-- 引入 Spring Cloud Config Client 相关依赖,作为配置中心的客户端,并实现自动化配置 --> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-config</artifactId> | ||
</dependency> | ||
|
||
<!-- 引入基于 Kafka 的 Spring Cloud Bus 的实现的依赖,并实现对其的自动配置 --> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-bus-kafka</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
...h-by-bus/src/main/java/cn/iocoder/springcloud/labx19/userapplication/UserApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cn.iocoder.springcloud.labx19.userapplication; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class UserApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(UserApplication.class, args); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...s/src/main/java/cn/iocoder/springcloud/labx19/userapplication/config/OrderProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cn.iocoder.springcloud.labx19.userapplication.config; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@ConfigurationProperties(prefix = "order") | ||
public class OrderProperties { | ||
|
||
/** | ||
* 订单支付超时时长,单位:秒。 | ||
*/ | ||
private Integer payTimeoutSeconds; | ||
|
||
/** | ||
* 订单创建频率,单位:秒 | ||
*/ | ||
private Integer createFrequencySeconds; | ||
|
||
public Integer getPayTimeoutSeconds() { | ||
return payTimeoutSeconds; | ||
} | ||
|
||
public OrderProperties setPayTimeoutSeconds(Integer payTimeoutSeconds) { | ||
this.payTimeoutSeconds = payTimeoutSeconds; | ||
return this; | ||
} | ||
|
||
public Integer getCreateFrequencySeconds() { | ||
return createFrequencySeconds; | ||
} | ||
|
||
public OrderProperties setCreateFrequencySeconds(Integer createFrequencySeconds) { | ||
this.createFrequencySeconds = createFrequencySeconds; | ||
return this; | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...rc/main/java/cn/iocoder/springcloud/labx19/userapplication/controller/DemoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cn.iocoder.springcloud.labx19.userapplication.controller; | ||
|
||
import cn.iocoder.springcloud.labx19.userapplication.config.OrderProperties; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.cloud.context.config.annotation.RefreshScope; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@RestController | ||
@RequestMapping("/demo") | ||
@RefreshScope | ||
public class DemoController { | ||
|
||
@Autowired | ||
private OrderProperties orderProperties; | ||
|
||
/** | ||
* 测试 @ConfigurationProperties 注解的配置属性类 | ||
*/ | ||
@GetMapping("/test01") | ||
public OrderProperties test01() { | ||
return orderProperties; | ||
} | ||
|
||
@Value(value = "${order.pay-timeout-seconds}") | ||
private Integer payTimeoutSeconds; | ||
@Value(value = "${order.create-frequency-seconds}") | ||
private Integer createFrequencySeconds; | ||
|
||
/** | ||
* 测试 @Value 注解的属性 | ||
*/ | ||
@GetMapping("/test02") | ||
public Map<String, Object> test02() { | ||
Map<String, Object> result = new HashMap<>(); | ||
result.put("payTimeoutSeconds", payTimeoutSeconds); | ||
result.put("createFrequencySeconds", createFrequencySeconds); | ||
return result; | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
...labx-19-sc-config-user-application-auto-refresh-by-bus/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Kafka 配置项,对应 KafkaProperties 配置类 | ||
kafka: | ||
bootstrap-servers: 127.0.0.1:9092 # 指定 Kafka Broker 地址,可以设置多个,以逗号分隔 |
9 changes: 9 additions & 0 deletions
9
...9/labx-19-sc-config-user-application-auto-refresh-by-bus/src/main/resources/bootstrap.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
spring: | ||
application: | ||
name: user-application | ||
|
||
cloud: | ||
# Spring Cloud Config Client 配置项,对应 ConfigClientProperties 类 | ||
config: | ||
uri: http://127.0.0.1:8888 # Spring Cloud Config Server 的地址 | ||
name: ${spring.application.name} # 读取的配置文件的名字,默认为 ${spring.application.name} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters