------- server pom ------------java
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cloud.framework</groupId>
<artifactId>server-cloud</artifactId>
<packaging>war</packaging>
<version>1.0.1-SNAPSHOT</version>
<name>server-cloud Maven Webapp</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.RC1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 讀取堆棧信息,刷新配置 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
<build>
<finalName>server-cloud</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
web
----------------- application.properties -------------------spring
server.port=9091apache
#
management.security.enabled=falsebootstrap
-----------------bootstrap.properties-----------------------------app
spring.application.name=cloud-serverjvm
#set profiles
spring.profiles.active=native
spring.cloud.config.server.native.search-locations=file:\\D:\\Users\\xuzhi268\\zhongchou\\config_profilesmaven
#file:///D:/Users/xuzhi268/zhongchou/config_profilesspring-boot
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.server.EnableConfigServer;ui
@SpringBootApplication
@EnableConfigServer
public class ServerCloudStarterRunner {
public static void main(String[] args) {
System.out.println("======= " + Thread.currentThread().getName() + " 開始啓動。");
new SpringApplicationBuilder(ServerCloudStarterRunner.class).web(true).run(args);
System.out.println("======= " + Thread.currentThread().getName() + " 啓動成功。");
}
}
---------------------client pom ------------------------
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cloud.framework</groupId>
<artifactId>sms-cloud</artifactId>
<packaging>war</packaging>
<version>1.0.1-SNAPSHOT</version>
<name>sms-cloud Maven Webapp</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.RC1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<finalName>sms-cloud</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
--------------bootstrap.properties-----------------
#set profiles
spring.application.name=sms-cloud
spring.cloud.config.uri=http://localhost:9091/
--------------application.properties-------------------
server.port=9092
management.security.enabled=false
@SpringBootApplication
@EnableDiscoveryClient
@ComponentScan(basePackages = {"com.cloud.framework.sms"})
public class SmsStarterRunner {
public static void main(String[] args) {
System.out.println("======" + Thread.currentThread().getName() + "[" + SmsStarterRunner.class.getSimpleName() + "]啓動開始。");
new SpringApplicationBuilder(SmsStarterRunner.class).web(true).run(args);
System.out.println("======" + Thread.currentThread().getName() + "[" + SmsStarterRunner.class.getSimpleName() + "]啓動成功。");
}
}
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;
@RestController
@RefreshScope
public class ParentController {
@Value("${sms.send.template.content}")
private String templateContent;
@GetMapping(value = "/sendSms.do")
public String sendSms (String body) {
try {
System.out.println("開始發送短信{" + body + "}");
System.out.println("短信模板內容{" + templateContent + "}");
} catch (Exception e) {
e.printStackTrace();
}
return body + " 發送成功";
}
}
--- http://localhost:9092/refresh -- 動態刷新客戶端配置