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-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的更多相关文章
- spring cloud config与eureka配合使用
前面两篇介绍了Spring Cloud Config服务端和客户端的简单配置,本篇介绍Spring Cloud Config与Eureka配合使用 前言 默认情况下,配置客户端启动时,都是通过配置属性 ...
- Spring Cloud(九)高可用的分布式配置中心 Spring Cloud Config 集成 Eureka 服务
上一篇文章,讲了SpringCloudConfig 集成Git仓库,这一篇我们讲一下SpringCloudConfig 配和 Eureka 注册中心一起使用 在分布式系统中,由于服务数量巨多,为了方便 ...
- 使用docker-compose运行微服务项目#eureka+config+auth+gateway+module
微服务架构中我们使用了必须的四个组件,eureka config gateway auth 其中config依赖eureka,auth依赖前两者,gateway又依赖auth 这样就确定了四个组件的启 ...
- Spring Cloud Eureka 实现服务注册与发现
微服务 是一种架构模式,跟具体的语言实现无关,微服务架构将业务逻辑分散到了各个服务当中,服务间通过网络层进行通信共同协作:这样一个应用就可以划分为多个服务单独来维护发布.构建一个可靠微服务系统是需要具 ...
- Spring Cloud Config 配置中心高可用
详细参见 <Spring Cloud 与 Docker微服务架构实战> p163-9.10 Spring Cloud Config 与 Eureka 配合使用 p163-9.12 Conf ...
- Spring Cloud Config 配置高可用集群
详细参考:<Sprin Cloud 与 Docker 微服务架构实战>p163-9.10节 spring cloud config 与 eureka 配合使用 我就不写了,请参见本书章节.
- Spring Cloud(9):Config配置中心
Config配置中心作用简单来讲:统一配置,方便管理 开源配置中心: 1.百度Disconf 2.阿里Diamand 3.Spring Cloud Config 搭建Config-Server 快速上 ...
- Spring Cloud Config 实现配置中心,看这一篇就够了
Spring Cloud Config 是 Spring Cloud 家族中最早的配置中心,虽然后来又发布了 Consul 可以代替配置中心功能,但是 Config 依然适用于 Spring Clou ...
- Spring-Cloud之Config配置中心-7
一.我们前面基本上都是讲解的Spring Cloud Netflix的组件,下面我们会重点说Spring Cloud Config分布式配置中心.为什么需要这个组件来管理配置呢?在分布式应用开发过程中 ...
随机推荐
- 开源项目源码解析-PhotoView 源码解析
1. 功能介绍 特性(Features): 支持 Pinch 手势自由缩放. 支持双击放大/还原. 支持平滑滚动. 在滑动父控件下能够运行良好.(例如:ViewPager) 支持基于 Matrix 变 ...
- 使用Node.js完成路由
首先先看一下文件的结构: 我想通过改变不同的路由进不同的页面, 先看这几个HTML页面: 404: <!DOCTYPE html> <html lang="en" ...
- PyQt4工具栏
工具栏 菜单对程序中的所有命令进行分组防治,而工具栏则提供了快速执行最常用命令的方法. #!/usr/bin/python # -*- coding:utf-8 -*- import sys from ...
- [译]Facebook广告基础--数字广告指南
广告商指南 原文链接:https://www.facebook.com/business/help/337584869654348/ Ads Help - Desktop > Learn Abo ...
- jquery类似方法的比较(二)
(1)append()&appendTo()&prepend()$prependTo() (2)after()&before()&insertAfter()&i ...
- Map集合中value()方法与keySet()、entrySet()区别 《转》
在Map集合中 values():方法是获取集合中的所有的值----没有键,没有对应关系, KeySet(): 将Map中所有的键存入到set集合中.因为set具备迭代器.所有可以迭代方式取出所有的键 ...
- 【BZOJ1717】[Usaco2006 Dec]Milk Patterns 产奶的模式 后缀数组
[BZOJ1717][Usaco2006 Dec]Milk Patterns Description 农夫John发现他的奶牛产奶的质量一直在变动.经过细致的调查,他发现:虽然他不能预见明天产奶的质量 ...
- Listview Section 多个标题以及内容
其中日期标题部分视图布局: 带图片的条目布局部分: 问题在于,如何在ListView中既有标题条目又有内容条目. 这里用到了设计模式中的Iterator模式.在java代码中示例有Iterator,可 ...
- 110道python题+理解(不断更新)
此篇题目在网上已经广为流传,但好多都不做解释,所以我想着自己一道一道的做一遍,并将相关涉及的做个补充,个人知识毕竟片面,有不足的地方还请大家多多指正 一.请用一行代码实现1-100之和 >> ...
- 170725、Kafka原理与技术
本文转载自:http://www.linkedkeeper.com/detail/blog.action?bid=1016 Kafka的基本介绍 Kafka最初由Linkedin公司开发,是一个分布式 ...