JAVA语言之(九)Java B2B2C o2o多用户商城-commonservice-config配置服务搭建
小标 2019-03-04 来源 : 阅读 606 评论 0

摘要:本文主要向大家介绍了JAVA语言之(九)Java B2B2C o2o多用户商城-commonservice-config配置服务搭建,通过具体的内容向大家展示,希望对大家学习JAVA语言有所帮助。

本文主要向大家介绍了JAVA语言之(九)Java B2B2C o2o多用户商城-commonservice-config配置服务搭建,通过具体的内容向大家展示,希望对大家学习JAVA语言有所帮助。

JAVA语言之(九)Java B2B2C o2o多用户商城-commonservice-config配置服务搭建

  1. 介绍



Spring Cloud Config为分布式系统中的外部配置提供服务器和客户端支持。使用Config Server,您可以在所有环境中管理应用程序的外部属性。客户端和服务器上的概念映射与Spring Environment和PropertySource抽象相同,因此它们与Spring应用程序非常契合,但可以与任何以任何语言运行的应用程序一起使用。随着应用程序通过从开发人员到测试和生产的部署流程,您可以管理这些环境之间的配置,并确定应用程序具有迁移时需要运行的一切。服务器存储后端的默认实现使用git,因此它轻松支持标签版本的配置环境,以及可以访问用于管理内容的各种工具。很容易添加替代实现,并使用Spring配置将其插入。



  1. 引入pom相关jar包,其中pom.xml配置如下:



<?xml version="1.0" encoding="UTF-8"?>  
<project xmlns="//maven.apache.org/POM/4.0.0" xmlns:xsi="//www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="//maven.apache.org/POM/4.0.0 //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>  



  1. 在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);  
    }  
}  



  1. 在src/main/resource下进行bootstrap.yml配置



server:   
port: 8888  
spring:  
  application:  
    name: commonservice-config-server  
  profiles:  
    active: discovery,native  
  cloud:  
    config:  
      server:  
        git:  
          uri: //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: //honghu:123456@localhost:8761/eureka/  
      honghuZone: //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: //honghu:123456@localhost:8761/eureka/  
      honghuZone: //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架构的搭建过程及如何运用于企业项目。

   

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注编程语言JAVA频道!

本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 1 不喜欢 | 0
看完这篇文章有何感觉?已经有1人表态,100%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程