Integrate spring cloud service architecture - commonservice-config configuration service setup

Keywords: Mobile Spring Maven Java git

  1. introduce

Spring Cloud Config provides server and client support for external configuration in distributed systems.With Config Server, you can manage the external properties of your application in all environments.The concept mappings on the client and server are the same as the abstractions of Spring Environment and ProertySource, so they fit well with Spring applications, but can be used with any application running in any language.As applications go through the deployment process from developers to testing and production, you can manage the configuration between these environments and determine that the application has everything it needs to run when migrating.The default implementation of the server storage backend uses git, so it easily supports the label version's configuration environment and accesses various tools for managing content.It is easy to add alternative implementations and insert them using the Spring configuration.

  1. Introduce a pom-related jar package where pom.xml is configured as follows:

Xml Code Collection Code

<?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>  
  1. ConfigApplication.java startup file configuration in src/main/java:

Java Code Collection Code

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. Configuring bootstrap.yml under src/main/resource

Java Code Collection Code

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  

Note: If you do not load configuration file information from a remote git or svn library, you can configure to load local addresses, such as configuring use under window s:

Java Code Collection Code

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: f`alse  

``

 //At this point, the entire config service item is configured!!

//From now on, I will record the construction process and essence of the recently developed spring cloud micro service cloud architecture, and help more friends interested in developing the spring cloud framework. Friends with e-commerce needs of spring cloud b2b2c can ask for penguins: 35,362,47259, let's discuss the construction process of the spring cloud architecture and how to use it.Enterprise projects.`

Posted by papapax on Wed, 27 Nov 2019 15:12:24 -0800