Spring Cloud Alibaba Nacos配置中心
This commit is contained in:
parent
2d19bbe2fa
commit
a1d8d7204f
|
|
@ -0,0 +1,62 @@
|
|||
<?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.2.5.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<groupId>cc.mrbird</groupId>
|
||||
<artifactId>spring-cloud-alibaba-nacos-config</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>spring-cloud-alibaba-nacos-config</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>
|
||||
<com-alibaba-cloud.version>2.2.0.RELEASE</com-alibaba-cloud.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-nacos-config</artifactId>
|
||||
</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>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>${com-alibaba-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>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package cc.mrbird.nacos;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringCloudAlibabaNacosConfigApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringCloudAlibabaNacosConfigApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package cc.mrbird.nacos.controller;
|
||||
|
||||
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.RestController;
|
||||
|
||||
/**
|
||||
* @author MrBird
|
||||
*/
|
||||
@RestController
|
||||
@RefreshScope
|
||||
public class TestController {
|
||||
|
||||
@Value("${message:null}")
|
||||
private String message;
|
||||
@Value("${ext1:null}")
|
||||
private String ext1;
|
||||
@Value("${ext2:null}")
|
||||
private String ext2;
|
||||
|
||||
@GetMapping("message")
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
@GetMapping("multi")
|
||||
public String multiConfig() {
|
||||
return String.format("ext1: %s ext2: %s", ext1, ext2);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
server:
|
||||
port: 8080
|
||||
spring:
|
||||
application:
|
||||
name: my-project
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
spring:
|
||||
# profiles:
|
||||
# active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
server-addr: localhost:8848
|
||||
# file-extension: yaml
|
||||
# prefix: febs
|
||||
# namespace: '2ef2186e-078c-4904-8643-ff5e90555456'
|
||||
# group: GROUP_A
|
||||
# extension-configs:
|
||||
# - dataId: ext-config-one.yaml
|
||||
# group: DEFAULT_GROUP
|
||||
# refresh: true
|
||||
# - dataId: ext-config-one.yaml
|
||||
# group: DEFAULT_GROUP
|
||||
# refresh: false
|
||||
shared-configs: ext-config-one.yaml,ext-config-two.yaml
|
||||
Loading…
Reference in New Issue