(六)java b2b2c springcloud shop 多用户商城系统源码-分布式配置中心(Spring Cloud Config)...

一、简介

在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件。在Spring Cloud中,有分布式配置中心组件spring cloud config ,它支持配置服务放在配置服务的内存中(即本地),也支持放在远程Git仓库中。在spring cloud config 组件中,分两个角色,一是config server,二是config client。

二、构建Config Server

创建一个spring-boot项目,取名为config-server,其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>
 
    <groupId>com.forezp</groupId>
    <artifactId>config-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
 
    <name>config-server</name>
    <description>Demo project for Spring Boot</description>
 
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
 
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR6</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>

在程序的入口Application类加上@EnableConfigServer注解开启配置服务器的功能,代码如下:

@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
 
    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}

需要在程序的配置文件application.properties文件配置以下:

spring.application.name=config-server
server.port=8888
spring.cloud.config.server.git.uri=https://github.com/forezp/SpringcloudConfig/
spring.cloud.config.server.git.searchPaths=respo
spring.cloud.config.label=master
spring.cloud.config.server.git.username=your username
spring.cloud.config.server.git.password=your password
  • spring.cloud.config.server.git.uri:配置git仓库地址
  • spring.cloud.config.server.git.searchPaths:配置仓库路径
  • spring.cloud.config.label:配置仓库的分支
  • spring.cloud.config.server.git.username:访问git仓库的用户名
  • spring.cloud.config.server.git.password:访问git仓库的用户密码

启动程序:访问http://localhost:8888/foo/dev

{"name":"foo","profiles":["dev"],"label":"master",
"version":"792ffc77c03f4b138d28e89b576900ac5e01a44b","state":null,"propertySources":[]}

架构代码如下:

"分布式b2b <wbr

 

Spring Cloud大型企业分布式微服务云构建的B2B2C电子商务平台源码请加企鹅求求:一零三八七七四六二六

转载于:https://my.oschina.net/u/4045192/blog/3010767

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1- 安装lombok插件 ## mysql - 下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads - 下载后按提示进行安装 - 导入document/sql下的mall.sql文件 ## redis - 下载地址:https://github.com/MicrosoftArchive/redis/releases - 下载后按提示进行安装 ## OSS - 该项目文件上传采用OSS,需要自行注册OSS账号并配置 - 首先将mall-admin\src\main\resources\application.properties文件中以aliyun.oss.开头的配置改为你自己的配置 - OSS上传文件需要配置跨域资共享(CORS)规则,参考文档:https://help.aliyun.com/document_detail/31928.html - 上传方式采用服务端签名后直传的形式,参考文档:https://help.aliyun.com/document_detail/31926.html ## mall-admin - 启动项目:直接运行com.macro.mall.MallAdminApplication的main方法即可 - 接口文档地址:http://localhost:8080/swagger-ui.html ## mall-search - 启动项目:直接运行com.macro.mall.search.MallSearchApplication的main方法即可 - 接口文档地址:http://localhost:8081/swagger-ui.html - 使用前需要先调用接口导入数据;http://localhost:8081/esProduct/importAll - 如出现无法启动的问题,可以先删除elasticsearch里面的数据再启动 ## mall-portal - 启动mall-portal项目:直接运行com.macro.mall.portal.MallPortalApplication的main方法即可 - 接口文档地址:http://localhost:8085/swagger-ui.html 1. 本地安装开发环境中的所有工具并启动 2. 克隆代码到本地,使用IDEA或Eclipse打开,并完成编译; 3. 安装 redis mysql 4. 在mysql中新建mall数据库,导入document/sql下的mall.sql文件; 5. 启动mall-admin项目:直接运行com.macro.mall.MallAdminApplication的main方法即可, 接口文档地址:http://localhost:8080/swagger-ui.html;  6. 启动mall-portal项目:直接运行com.macro.mall.portal.MallPortalApplication的main方法即可, 接口文档地址:http://localhost:8085/swagger-ui.html;  7. 克隆mall-admin-web项目,并导入到IDEA中并完成编译传送门,需要安装node环境,然后到项目下; 8. 运行命令:npm install 然后执行 npm run dev,访问地址:http://localhost:8090 即可打开后台管理系统页面; 9. 克隆Mall-Vue-master项目,并导入到IDEA中并完成编译传送门; 10. 运行命令:npm run dev,访问地址: 即可打开pc商城页面; 11. 克隆vue-jd-master项目,并导入到IDEA中并完成编译传送门; 12. 运行命令:npm run dev,访问地址: 即可打开h5商城页面; 13. 下载小程序 用微信开发工具打卡就可以访问   https://gitee.com/zscat-platform/mall   功能预览   http://www.yjlive.cn:8090/#/home   https://gitee.com/zscat-platform/mall/wikis/pages 645

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值