Skip to content

Commit 9ff6e9a

Browse files
dyc87112zhaiyongchao
authored andcommitted
Spring Cloud构建微服务架构(四)分布式配置中心
1 parent 6a71dfc commit 9ff6e9a

File tree

11 files changed

+128
-5
lines changed

11 files changed

+128
-5
lines changed

Chapter9-1-4/config-client/pom.xml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.didispace</groupId>
7+
<artifactId>config-client</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>config-client</name>
12+
<description>Spring Cloud project</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.3.5.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>1.8</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-test</artifactId>
31+
<scope>test</scope>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-web</artifactId>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.springframework.cloud</groupId>
41+
<artifactId>spring-cloud-starter-config</artifactId>
42+
</dependency>
43+
44+
</dependencies>
45+
46+
<dependencyManagement>
47+
<dependencies>
48+
<dependency>
49+
<groupId>org.springframework.cloud</groupId>
50+
<artifactId>spring-cloud-dependencies</artifactId>
51+
<version>Brixton.RELEASE</version>
52+
<type>pom</type>
53+
<scope>import</scope>
54+
</dependency>
55+
</dependencies>
56+
</dependencyManagement>
57+
58+
<build>
59+
<plugins>
60+
<plugin>
61+
<groupId>org.springframework.boot</groupId>
62+
<artifactId>spring-boot-maven-plugin</artifactId>
63+
</plugin>
64+
</plugins>
65+
</build>
66+
67+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.didispace;
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication;
4+
import org.springframework.boot.builder.SpringApplicationBuilder;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
new SpringApplicationBuilder(Application.class).web(true).run(args);
11+
}
12+
13+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.didispace.web;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.cloud.context.config.annotation.RefreshScope;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
@RefreshScope
9+
@RestController
10+
class TestController {
11+
12+
@Value("${from}")
13+
private String from;
14+
15+
@RequestMapping("/from")
16+
public String from() {
17+
18+
return this.from;
19+
}
20+
21+
public void setFrom(String from) {
22+
this.from = from;
23+
}
24+
25+
public String getFrom() {
26+
return from;
27+
}
28+
29+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
spring.application.name=didispace
2+
spring.cloud.config.profile=dev
3+
spring.cloud.config.uri=http://localhost:7001/
4+
5+
server.port=7002
6+
7+
8+
9+
10+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from=local-dev
1+
from=git-dev
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from=local-prod
1+
from=git-prod
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from=local-test
1+
from=git-test

Chapter9-1-4/config-server/src/main/resources/application.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
spring.application.name=config-server
22
server.port=7001
33

4+
# git¹ÜÀíÅäÖÃ
45
spring.cloud.config.server.git.uri=http://git.oschina.net/didispace/SpringBoot-Learning/
5-
spring.cloud.config.server.git.searchPaths=Chapter9-1-4
6+
spring.cloud.config.server.git.searchPaths=Chapter9-1-4/config-repo
67
spring.cloud.config.server.git.username=username
78
spring.cloud.config.server.git.password=password
89

910
# ¿ªÆô±¾µØÅäÖÃ
10-
#spring.profiles.active=native
11+
spring.profiles.active=native
1112

1213

1314

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from=local-dev
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from=local-prod
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from=local-test

0 commit comments

Comments
 (0)