springcloud20---Config加入eureka
生活随笔
收集整理的這篇文章主要介紹了
springcloud20---Config加入eureka
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Config server也可以加用戶名和密碼。Config client通過用戶名和密碼訪問。
Config server也可以做成高可用集群。
Config與eureka配置使用。把Config server注冊到eureka。Config client也要注冊到eureka。
package com.itmuch.cloud;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.config.server.EnableConfigServer;@SpringBootApplication @EnableConfigServer @EnableDiscoveryClient public class ServerApplication {public static void main(String[] args) {SpringApplication.run(ServerApplication.class, args);} } server:port: 8080 spring:cloud:config:server:git:uri: https://git.oschina.net/it-much/config-repo-51cto-video username: password: application:name: microservice-config-server-eurekaeureka: #config-server注冊到eurekaclient:serviceUrl:defaultZone: http://user:password123@localhost:8761/eureka instance:prefer-ip-address: true <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/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.itmuch.cloud</groupId><artifactId>microservice-spring-cloud</artifactId><version>0.0.1-SNAPSHOT</version></parent><artifactId>microservice-config-server-eureka</artifactId><packaging>jar</packaging><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><!-- config-server的依賴,config-server注冊到rureka --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-config-server</artifactId></dependency><!-- eureka-client的依賴 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId></dependency></dependencies><build><defaultGoal>compile</defaultGoal><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.12.3</version><configuration><groups>unit</groups></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.0</version><configuration><verbose>true</verbose><fork>true</fork><compilerVersion>1.5</compilerVersion></configuration></plugin></plugins></build> </project> package com.itmuch.cloud;import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;@RestController public class ConfigClientController {@Value("${profile}")private String profile;@GetMapping("/profile")public String getProfile() {return this.profile;} } package com.itmuch.cloud;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;@SpringBootApplication @EnableDiscoveryClient public class ConfigServerApplication {public static void main(String[] args) {SpringApplication.run(ConfigServerApplication.class, args);} }
application.yml
server:port: 8081bootstrap.yml
spring:cloud:config:discovery:enabled: trueservice-id: microservice-config-server-eureka #config server在eureka的名字application:name: foobareureka: #把config client注冊到eurekaclient:serviceUrl:defaultZone: http://user:password123@localhost:8761/eureka instance:prefer-ip-address: true <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/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.itmuch.cloud</groupId><artifactId>microservice-spring-cloud</artifactId><version>0.0.1-SNAPSHOT</version></parent><artifactId>microservice-config-client-eureka</artifactId><packaging>jar</packaging><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-config</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency></dependencies></project>?
?
?
?
?
?
配置屬性加解密:
配置在git倉庫里面是明文,
下載jce8 :
http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html
下載之后解壓:
里面是2個加解密的策略文件。用這2個策略文件替換jdk里面的策略文件就可以了。
轉載于:https://www.cnblogs.com/yaowen/p/9184295.html
總結
以上是生活随笔為你收集整理的springcloud20---Config加入eureka的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【数据结构】——快速排序
- 下一篇: SHA256算法原理介绍以及实现