Skip to content

Commit a1d8d72

Browse files
committedMar 16, 2020
Spring Cloud Alibaba Nacos配置中心
1 parent 2d19bbe commit a1d8d72

File tree

5 files changed

+130
-0
lines changed

5 files changed

+130
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.2.5.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
12+
<groupId>cc.mrbird</groupId>
13+
<artifactId>spring-cloud-alibaba-nacos-config</artifactId>
14+
<version>0.0.1-SNAPSHOT</version>
15+
<name>spring-cloud-alibaba-nacos-config</name>
16+
<description>Demo project for Spring Boot</description>
17+
18+
<properties>
19+
<java.version>1.8</java.version>
20+
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>
21+
<com-alibaba-cloud.version>2.2.0.RELEASE</com-alibaba-cloud.version>
22+
</properties>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-web</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>com.alibaba.cloud</groupId>
31+
<artifactId>spring-cloud-alibaba-nacos-config</artifactId>
32+
</dependency>
33+
</dependencies>
34+
35+
<dependencyManagement>
36+
<dependencies>
37+
<dependency>
38+
<groupId>org.springframework.cloud</groupId>
39+
<artifactId>spring-cloud-dependencies</artifactId>
40+
<version>${spring-cloud.version}</version>
41+
<type>pom</type>
42+
<scope>import</scope>
43+
</dependency>
44+
<dependency>
45+
<groupId>com.alibaba.cloud</groupId>
46+
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
47+
<version>${com-alibaba-cloud.version}</version>
48+
<type>pom</type>
49+
<scope>import</scope>
50+
</dependency>
51+
</dependencies>
52+
</dependencyManagement>
53+
54+
<build>
55+
<plugins>
56+
<plugin>
57+
<groupId>org.springframework.boot</groupId>
58+
<artifactId>spring-boot-maven-plugin</artifactId>
59+
</plugin>
60+
</plugins>
61+
</build>
62+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cc.mrbird.nacos;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class SpringCloudAlibabaNacosConfigApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(SpringCloudAlibabaNacosConfigApplication.class, args);
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package cc.mrbird.nacos.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+
/**
9+
* @author MrBird
10+
*/
11+
@RestController
12+
@RefreshScope
13+
public class TestController {
14+
15+
@Value("${message:null}")
16+
private String message;
17+
@Value("${ext1:null}")
18+
private String ext1;
19+
@Value("${ext2:null}")
20+
private String ext2;
21+
22+
@GetMapping("message")
23+
public String getMessage() {
24+
return this.message;
25+
}
26+
27+
@GetMapping("multi")
28+
public String multiConfig() {
29+
return String.format("ext1: %s ext2: %s", ext1, ext2);
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
server:
2+
port: 8080
3+
spring:
4+
application:
5+
name: my-project
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
spring:
2+
# profiles:
3+
# active: dev
4+
cloud:
5+
nacos:
6+
config:
7+
server-addr: localhost:8848
8+
# file-extension: yaml
9+
# prefix: febs
10+
# namespace: '2ef2186e-078c-4904-8643-ff5e90555456'
11+
# group: GROUP_A
12+
# extension-configs:
13+
# - dataId: ext-config-one.yaml
14+
# group: DEFAULT_GROUP
15+
# refresh: true
16+
# - dataId: ext-config-one.yaml
17+
# group: DEFAULT_GROUP
18+
# refresh: false
19+
shared-configs: ext-config-one.yaml,ext-config-two.yaml

0 commit comments

Comments
 (0)
Please sign in to comment.