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-eureka eureka: #config-server注册到eureka
client:
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: 8081

bootstrap.yml

spring:
cloud:
config:
discovery:
enabled: true
service-id: microservice-config-server-eureka #config server在eureka的名字
application:
name: foobar eureka: #把config client注册到eureka
client:
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里面的策略文件就可以了。

springcloud20---Config加入eureka的更多相关文章

  1. spring cloud config与eureka配合使用

    前面两篇介绍了Spring Cloud Config服务端和客户端的简单配置,本篇介绍Spring Cloud Config与Eureka配合使用 前言 默认情况下,配置客户端启动时,都是通过配置属性 ...

  2. Spring Cloud(九)高可用的分布式配置中心 Spring Cloud Config 集成 Eureka 服务

    上一篇文章,讲了SpringCloudConfig 集成Git仓库,这一篇我们讲一下SpringCloudConfig 配和 Eureka 注册中心一起使用 在分布式系统中,由于服务数量巨多,为了方便 ...

  3. 使用docker-compose运行微服务项目#eureka+config+auth+gateway+module

    微服务架构中我们使用了必须的四个组件,eureka config gateway auth 其中config依赖eureka,auth依赖前两者,gateway又依赖auth 这样就确定了四个组件的启 ...

  4. Spring Cloud Eureka 实现服务注册与发现

    微服务 是一种架构模式,跟具体的语言实现无关,微服务架构将业务逻辑分散到了各个服务当中,服务间通过网络层进行通信共同协作:这样一个应用就可以划分为多个服务单独来维护发布.构建一个可靠微服务系统是需要具 ...

  5. Spring Cloud Config 配置中心高可用

    详细参见 <Spring Cloud 与 Docker微服务架构实战> p163-9.10 Spring Cloud Config 与 Eureka 配合使用 p163-9.12 Conf ...

  6. Spring Cloud Config 配置高可用集群

    详细参考:<Sprin Cloud 与 Docker 微服务架构实战>p163-9.10节 spring cloud config 与 eureka 配合使用 我就不写了,请参见本书章节.

  7. Spring Cloud(9):Config配置中心

    Config配置中心作用简单来讲:统一配置,方便管理 开源配置中心: 1.百度Disconf 2.阿里Diamand 3.Spring Cloud Config 搭建Config-Server 快速上 ...

  8. Spring Cloud Config 实现配置中心,看这一篇就够了

    Spring Cloud Config 是 Spring Cloud 家族中最早的配置中心,虽然后来又发布了 Consul 可以代替配置中心功能,但是 Config 依然适用于 Spring Clou ...

  9. Spring-Cloud之Config配置中心-7

    一.我们前面基本上都是讲解的Spring Cloud Netflix的组件,下面我们会重点说Spring Cloud Config分布式配置中心.为什么需要这个组件来管理配置呢?在分布式应用开发过程中 ...

随机推荐

  1. shiro-filter执行流程

    web中 在xml中配置 <filter> <filter-name>shiroFilter</filter-name> <filter-class>o ...

  2. thinkphp5.0开发规范

    命名规范 ThinkPHP5遵循PSR-2命名规范和PSR-4自动加载规范,并且注意如下规范: 目录和文件 目录不强制规范,驼峰及小写+下划线模式均支持: 类库.函数文件统一以.php为后缀: 类的文 ...

  3. eui.Button 上放置两张图片

    有时按钮会有一个需求.放置一个按钮底图,按钮文字是特效字体,也是一张图. 1   1个普通按钮 <e:Button label="> <e:skinName> < ...

  4. C++ 初始化函数的实现

    http://www.cppblog.com/xlshcn/archive/2007/11/21/37088.aspx

  5. 03.JMS深入

    1.JMS API     JMS API可以分为3个主要部分:公共API.点对点API和发布/订阅API.在JMS1.1中,公共API可被用于向一个队列或主题发送消息,或从其中接收消息.点对点API ...

  6. Hadoop讲解

    1.简介 Hadoop是一款开源的大数据通用处理平台,其提供了分布式存储和分布式离线计算,适合大规模数据.流式数据(写一次,读多次),不适合低延时的访问.大量的小文件以及频繁修改的文件. *Hadoo ...

  7. pta 习题集5-17 哥尼斯堡的“七桥问题”

    哥尼斯堡是位于普累格河上的一座城市,它包含两个岛屿及连接它们的七座桥,如下图所示. 可否走过这样的七座桥,而且每桥只走过一次?瑞士数学家欧拉(Leonhard Euler,1707-1783)最终解决 ...

  8. nginx repos

    vim /etc/yum.repos.d/nginx.repo 然后将下面的内容复制进去: [nginx] name=nginx repo baseurl=http://nginx.org/packa ...

  9. 7.1 - CRM系统

    一.简介 crm 客户关系管理软件 ( Customer Relationship Management ) ( 详细内容 ) stark组件(仿admin组件)( 详细内容 ) rbac组件(基于角 ...

  10. Treasure Exploration---poj2594(传递闭包Floyd+最小路径覆盖)

    题目链接:http://poj.org/problem?id=2594 在外星上有n个点需要机器人去探险,有m条单向路径.问至少需要几个机器人才能遍历完所有的点,一个点可以被多个机器人经过(这就是和单 ...