Spring Cloud云服务架构 - commonservice-config配置服务搭建
1. 介绍
Spring Cloud Config为分布式系统中的外部配置提供服务器和客户端支持。使用Config Server,您可以在所有环境中管理应用程序的外部属性。客户端和服务器上的概念映射与Spring Environment和PropertySource抽象相同,因此它们与Spring应用程序非常契合,但可以与任何以任何语言运行的应用程序一起使用。随着应用程序通过从开发人员到测试和生产的部署流程,您可以管理这些环境之间的配置,并确定应用程序具有迁移时需要运行的一切。服务器存储后端的默认实现使用git,因此它轻松支持标签版本的配置环境,以及可以访问用于管理内容的各种工具。很容易添加替代实现,并使用Spring配置将其插入。
2. 引入pom相关jar包,其中pom.xml配置如下:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <parent>
<groupId>com.ml.honghu</groupId>
<artifactId>commonservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent> <artifactId>commonservice-config</artifactId>
<packaging>jar</packaging> <name>commonservice-config</name>
<description>Config Server</description> <dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</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-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>1</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
<execution>
<id>2</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
3. 在src/main/java进行ConfigApplication.java启动文件配置:
package com.ml.honghu; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @EnableConfigServer
@EnableEurekaClient
@SpringBootApplication
public class ConfigApplication { public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
4. 在src/main/resource下进行bootstrap.yml配置
server:
port: 8888
spring:
application:
name: commonservice-config-server
profiles:
active: discovery,native
cloud:
config:
server:
git:
uri: http://192.168.0.254/honghu.../honghu-config.git
username: honghu
password: 123456
searchPaths: config-dev
security:
basic:
enabled: true
user:
name: honghu
password: 123456
eureka:
client:
serviceUrl:
defaultZone: http://honghu:123456@localhost:8761/eureka/
honghuZone: http://honghu:123456@localhost:8761/eureka/
registry-fetch-interval-seconds: 300
availability-zones:
honghu: honghuZone
instance:
prefer-ip-address: true
metadataMap:
version: 1.0
variant: A
user: ${security.user.name}
password: ${security.user.password}
management:
security:
enabled: false
注意: 如果不从远程git或者svn库加载配置文件信息,可以配置加载本地地址,比如window下配置使用:
server:
port: 8888
spring:
application:
name: commonservice-config-server
profiles:
active: discovery,native
cloud:
config:
server:
<span style="color: #ff0000;">native.searchLocations: d:/honghu-config</span>
security:
basic:
enabled: true
user:
name: honghu
password: 123456
eureka:
client:
serviceUrl:
defaultZone: http://honghu:123456@localhost:8761/eureka/
honghuZone: http://honghu:123456@localhost:8761/eureka/
registry-fetch-interval-seconds: 300
availability-zones:
honghu: honghuZone
instance:
prefer-ip-address: true
metadataMap:
version: 1.0
variant: A
user: ${security.user.name}
password: ${security.user.password}
management:
security:
enabled: false
到此,整个config服务项目配置完毕!!
从现在开始,我这边会将近期研发的spring cloud微服务云架构的搭建过程和精髓记录下来,帮助更多有兴趣研发spring cloud框架的朋友,大家来一起探讨spring cloud架构的搭建过程及如何运用于企业项目。
Spring Cloud云服务架构 - commonservice-config配置服务搭建的更多相关文章
- Spring Cloud(十四)Config 配置中心与客户端的使用与详细
前言 在上一篇 文章 中我们直接用了本应在本文中配置的Config Server,对Config也有了一个基本的认识,即 Spring Cloud Config 是一种用来动态获取Git.SVN.本地 ...
- Spring Cloud(9):Config配置中心
Config配置中心作用简单来讲:统一配置,方便管理 开源配置中心: 1.百度Disconf 2.阿里Diamand 3.Spring Cloud Config 搭建Config-Server 快速上 ...
- 整合SPRING CLOUD云服务架构 - 企业分布式微服务云架构构建
整合SPRING CLOUD云服务架构 - 企业分布式微服务云架构构建 1. 介绍 Commonservice-system是一个大型分布式.微服务.面向企业的JavaEE体系快速研发平台,基于模 ...
- 第1章 Spring Cloud 构建微服务架构(一)服务注册与发现
一.Spring Cloud 简介 Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中的配置管理.服务发现.断路器.智能路由.微代理.控制总 ...
- Spring Cloud构建微服务架构(二)服务消费者
Netflix Ribbon is an Inter Process Communication (IPC) cloud library. Ribbon primarily provides clie ...
- Spring Cloud构建微服务架构(五)服务网关
通过之前几篇Spring Cloud中几个核心组件的介绍,我们已经可以构建一个简略的(不够完善)微服务架构了.比如下图所示: 我们使用Spring Cloud Netflix中的Eureka实现了服务 ...
- Spring Cloud系列(一):微服务架构简介
一.微服务概述 1.微服务是什么 微服务架构的核心就是服务的拆分,把传统的单体式应用,根据一定的维度(比如业务)拆分为一个一个的服务,每一个服务都有自身特定的功能,又都能够独立的部署,甚至可以拥有自己 ...
- spring cloud深入学习(一)-----什么是微服务?什么是rpc?spring cloud简介
近年来,微服务非常的流行,那么为什么是它?简单介绍一下. 为什么是微服务? 微服务架构是一种将单应用程序作为一套小型服务开发的方法,每种应用程序都在其自己的进程中运行,并与轻量级机制(通常是HTTP资 ...
- Spring Cloud Alibaba基础教程:Nacos配置的多环境管理
前情回顾: <Spring Cloud Alibaba基础教程:使用Nacos实现服务注册与发现> <Spring Cloud Alibaba基础教程:支持的几种服务消费方式> ...
- Spring Cloud学习笔记【一】Eureka服务注册与发现
Spring Cloud Eureka 是 Spring Cloud Netflix 微服务套件的一部分,基于 Netflix Eureka 做了二次封装,主要负责完成微服务架构中的服务治理功能,服务 ...
随机推荐
- spring boot-13.数据访问
1.spring boot 的自动配置提供的方便快捷的数据库操作服务,只需要进行少量配置即可连接数据库.spring boot 在org.springframework.boot.autoconfig ...
- spring配置添加多个事务(转)
大多数项目只需要一个事务管理器.然而,有些项目为了提高效率.或者有多个完全不同又不相干的数据源,最好用多个事务管理器.机智的Spring的Transactional管理已经考虑到了这一点,首先分别定义 ...
- java实现整数计算器
计算器代码 package stack; import java.util.ArrayList; import java.util.List; import java.util.Scanner; im ...
- Python文件的几种读写方式
1). "w "写模式,它是不能读的,如果用w模式打开一个已经存在的文件,会清空以前的文件内容,重新写 "w+ "是读写内容,只要沾上w,肯定会清空原来的文件2 ...
- 小白学习django第二站-模版配置
上一站说道app创建,接下来我们来配置app的url路由 首先需要到setting.py中添加book这个app, 再到django_test文件里的urls添加路由 include() : 这个函数 ...
- python计算1~100的和,1~100奇数的和,1~100偶数的和,一条代码求1~100的和
1.计算1~100的数之和----for循环实现1~100的和 sum1 = ,): sum1 = sum1 + i i += print(f"1-100之间的和是:{sum1}" ...
- python3的一些文件操作的脚手架
用python把原来的脚本重构了一下,其中写了文件操作的一些函数,如下: import os import shutil import hashlib import stat #查找文件夹中的某个文件 ...
- python操作redis用法详解
python操作redis用法详解 转载地址 1.redis连接 redis提供两个类Redis和StrictRedis用于实现Redis的命令,StrictRedis用于实现大部分官方的命令,并使用 ...
- 有准备的面试才能拿到更好的 Offer
http://www.sohu.com/a/331411917_181657 前几天有读者问我,工作不顺利辞职了.本来以为凭借自己的能力和工作经验可以轻松找到更好的工作,结果投了简历,约面试的很少,面 ...
- P1058 立体图题解
小渊是个聪明的孩子,他经常会给周围的小朋友们将写自己认为有趣的内容.最近,他准备给小朋友们讲解立体图,请你帮他画出立体图. 小渊有一块面积为m \times nm×n的矩形区域,上面有m \times ...
