Skip to content

Commit 4014699

Browse files
committedNov 16, 2018
Spring Cloud Config统一配置管理
1 parent 3b61b22 commit 4014699

File tree

18 files changed

+373
-0
lines changed

18 files changed

+373
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.example</groupId>
7+
<artifactId>Eureka-Service</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>Eureka-Service</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.13.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencyManagement>
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.springframework.cloud</groupId>
31+
<artifactId>spring-cloud-dependencies</artifactId>
32+
<version>Edgware.SR3</version>
33+
<type>pom</type>
34+
<scope>import</scope>
35+
</dependency>
36+
</dependencies>
37+
</dependencyManagement>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>org.springframework.cloud</groupId>
42+
<artifactId>spring-cloud-starter-eureka-server</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-starter-security</artifactId>
47+
</dependency>
48+
49+
</dependencies>
50+
51+
<repositories>
52+
<repository>
53+
<id>nexus-aliyun</id>
54+
<name>Nexus aliyun</name>
55+
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
56+
</repository>
57+
</repositories>
58+
59+
<build>
60+
<plugins>
61+
<plugin>
62+
<groupId>org.springframework.boot</groupId>
63+
<artifactId>spring-boot-maven-plugin</artifactId>
64+
</plugin>
65+
</plugins>
66+
</build>
67+
68+
69+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.example.demo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
6+
7+
8+
@EnableEurekaServer
9+
@SpringBootApplication
10+
public class DemoApplication {
11+
public static void main(String[] args) {
12+
SpringApplication.run(DemoApplication.class, args);
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
server:
2+
port: 8080
3+
4+
spring:
5+
application:
6+
name: Eureka-Server
7+
8+
eureka:
9+
instance:
10+
hostname: peer1
11+
client:
12+
serviceUrl:
13+
defaultZone: http://mrbird:123456@peer2:8081/eureka/
14+
server:
15+
enable-self-preservation: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
server:
2+
port: 8081
3+
4+
spring:
5+
application:
6+
name: Eureka-Server
7+
8+
eureka:
9+
instance:
10+
hostname: peer2
11+
client:
12+
serviceUrl:
13+
defaultZone: http://mrbird:123456@peer1:8080/eureka/
14+
server:
15+
enable-self-preservation: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
security:
2+
basic:
3+
enabled: true
4+
user:
5+
name: mrbird
6+
password: 123456
7+
spring:
8+
profiles:
9+
active: peer1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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>cc.mrbird</groupId>
7+
<artifactId>Config-Client</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>demo</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.13.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencyManagement>
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.springframework.cloud</groupId>
31+
<artifactId>spring-cloud-dependencies</artifactId>
32+
<version>Edgware.SR3</version>
33+
<type>pom</type>
34+
<scope>import</scope>
35+
</dependency>
36+
</dependencies>
37+
</dependencyManagement>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-starter</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-starter-web</artifactId>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.springframework.cloud</groupId>
50+
<artifactId>spring-cloud-starter-config</artifactId>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-starter-actuator</artifactId>
55+
</dependency>
56+
<!--<dependency>-->
57+
<!--<groupId>org.springframework.cloud</groupId>-->
58+
<!--<artifactId>spring-cloud-starter-eureka</artifactId>-->
59+
<!--</dependency>-->
60+
</dependencies>
61+
62+
<build>
63+
<plugins>
64+
<plugin>
65+
<groupId>org.springframework.boot</groupId>
66+
<artifactId>spring-boot-maven-plugin</artifactId>
67+
</plugin>
68+
</plugins>
69+
</build>
70+
71+
72+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package cc.mrbird.demo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6+
7+
@SpringBootApplication
8+
// @EnableDiscoveryClient
9+
public class DemoApplication {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(DemoApplication.class, args);
13+
}
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package cc.mrbird.demo.controller;
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.GetMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
@RestController
9+
@RefreshScope
10+
public class TestController {
11+
12+
@Value("${message}")
13+
private String message;
14+
15+
@GetMapping("message")
16+
public String getMessage() {
17+
return this.message;
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
spring:
2+
application:
3+
name: febs
4+
cloud:
5+
config:
6+
profile: dev
7+
label: master
8+
uri: http://localhost:12580
9+
username: mrbird
10+
password: 123456
11+
# discovery:
12+
# enabled: true
13+
# service-id: config-server
14+
15+
#eureka:
16+
# client:
17+
# serviceUrl:
18+
# defaultZone: http://mrbird:123456@peer1:8080/eureka/,http://mrbird:123456@peer2:8081/eureka/
19+
20+
server:
21+
port: 12581
22+
management:
23+
security:
24+
enabled: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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>cc.mrbird</groupId>
7+
<artifactId>Config-Server</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>demo</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.13.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencyManagement>
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.springframework.cloud</groupId>
31+
<artifactId>spring-cloud-dependencies</artifactId>
32+
<version>Edgware.SR3</version>
33+
<type>pom</type>
34+
<scope>import</scope>
35+
</dependency>
36+
</dependencies>
37+
</dependencyManagement>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-starter</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.springframework.cloud</groupId>
46+
<artifactId>spring-cloud-config-server</artifactId>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.springframework.boot</groupId>
50+
<artifactId>spring-boot-starter-security</artifactId>
51+
</dependency>
52+
<!--<dependency>-->
53+
<!--<groupId>org.springframework.cloud</groupId>-->
54+
<!--<artifactId>spring-cloud-starter-eureka</artifactId>-->
55+
<!--</dependency>-->
56+
</dependencies>
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+
68+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cc.mrbird.demo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6+
import org.springframework.cloud.config.server.EnableConfigServer;
7+
8+
@SpringBootApplication
9+
@EnableConfigServer
10+
// @EnableDiscoveryClient
11+
public class DemoApplication {
12+
13+
public static void main(String[] args) {
14+
SpringApplication.run(DemoApplication.class, args);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
spring:
2+
application:
3+
name: config-server
4+
cloud:
5+
config:
6+
server:
7+
git:
8+
uri: xxx
9+
username: xxx
10+
password: xxx
11+
# search-paths: '{application}'
12+
clone-on-start: true
13+
14+
server:
15+
port: 12580
16+
security:
17+
user:
18+
name: mrbird
19+
password: 123456
20+
21+
#eureka:
22+
# client:
23+
# serviceUrl:
24+
# defaultZone: http://mrbird:123456@peer1:8080/eureka/,http://mrbird:123456@peer2:8081/eureka/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#encrypt:
2+
## key: hello
3+
4+
#encrypt:
5+
# key-store:
6+
# location: classpath:config-server.keystore
7+
# alias: Config-Server
8+
# password: 123456
9+
# secret: 654321
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
message: 'dev properties (master v1.0)'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
message: 'pro properties (master v1.0)'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
message: 'test properties (master v1.0)'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
message: 'default properties (master v1.0)'

0 commit comments

Comments
 (0)
Please sign in to comment.