java版电子商务spring cloud分布式微服务b2b2c社交电商- commonservice-config配置服务搭建
介绍
Spring Cloud Config为分布式系统中的外部配置提供服务器和客户端支持。使用Config Server,您可以在所有环境中管理应用程序的外部属性。客户端和服务器上的概念映射与Spring Environment和PropertySource抽象相同,因此它们与Spring应用程序非常契合,但可以与任何以任何语言运行的应用程序一起使用。随着应用程序通过从开发人员到测试和生产的部署流程,您可以管理这些环境之间的配置,并确定应用程序具有迁移时需要运行的一切。服务器存储后端的默认实现使用git,因此它轻松支持标签版本的配置环境,以及可以访问用于管理内容的各种工具。很容易添加替代实现,并使用Spring配置将其插入。
引入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>
在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架构的搭建过程及如何运用于企业项目。
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
初识SpringCloud(1)SpringCloud简介与5大常用组件
springcloud springcloud是微服务架构的集大成者,将一系列优秀的组件进行了整合。基于springboot构建,对我们熟悉spring的程序员来说,上手比较容易。 通过一些简单的注解,我们就可以快速的在应用中配置一下常用模块并构建庞大的分布式系统。 SpringCloud的组件相当繁杂,拥有诸多子项目。重点关注Netflix springcloud的版本说明: springcloud项目是由多个独立项目集合而成的,每个项目都是独立的,各自进行自己的迭代和版本发布。所以springcloud不方便使用版本号来管理,而是使用版本名。以避免和子项目版本号的冲突。 版本名的来源是伦敦的地铁站名,以字母排序。比如最早的Release版本为Angel,第二个Release版本为Brixton。。。 当一个版本的update积累的比较多或者解决了一个严重bug时,会发布一个ServiceRelease版本,简称SR,后面带的数字就是该大版本下的第一次发布 从官网上看,springcloud的F版本是基于springboot的2.0.x构建,之前的是基于springboot的1.5....
- 下一篇
DTCC 2019 | 把握数据库发展趋势 DBA应如何避免“踩坑”?
摘要:在DTCC 2019大会上,阿里云智能数据库产品事业部高级产品专家萧少聪做了题为《如何构建云时代DBA的知识体系》的演讲,进行云时代以后,IT行业各工种的职责都在发生变化,云数据库使得日常DBA管理实现更多的自动化,大大提高日常管理效率,同时也对于企业整体投资产出可以更快获得成效。面对云数据库的发展趋势,DBA应如何避免“踩坑”呢?本文就为大家揭晓答案。 专家简介:萧少聪(花名:铁庵),阿里云智能数据库产品事业部高级产品专家,PostgreSQL中国社区常委。 直播回放 链接:https://yq.aliyun.com/live/1046 议题PPT下载,戳这里! https://yq.aliyun.com/download/3562 本文将主要围绕以下四个方面进行分享: 管理模式的变化 云数据库VS.自建数据库 云DBA知识体系构成 如何成为
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- MySQL8.0.19开启GTID主从同步CentOS8
- Linux系统CentOS6、CentOS7手动修改IP地址
- SpringBoot2全家桶,快速入门学习开发网站教程
- CentOS8编译安装MySQL8.0.19
- SpringBoot2整合Redis,开启缓存,提高访问速度
- 设置Eclipse缩进为4个空格,增强代码规范
- CentOS7,CentOS8安装Elasticsearch6.8.6
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作