Git tools

Download: git-scm.com/download/wi…

After downloading, configure the user name and email

  1. The inputgit config --listDisplays the current Config configuration

  • The user name and mailbox are not configured
  1. The inputgit config --global user.name "suisuinian"Configuring a User Name
  2. The inputgit config --global user.email "[email protected]"Configure your email
  3. Input againgit config --listDisplays the current Config configuration

  • The user name and mailbox have been configured

Use code cloud for code hosting

  1. Register a code cloud account first
  2. Get the SSH public key (using Git tools)
    • The inputssh-keygen -t rsa -C "[email protected]"
    • Press Enter three times to get the public key
    • The inputcat ~/.ssh/id_rsa.pubLook at the public key

  1. Set the SSH Public key (on the Code Cloud)

Create a repository on the code cloud and download the remote repository locally

Fill in the information you need to fill in

Implement local and remote repository calls

  1. Get the SSH address of the remote repository you created[email protected]:asfasfasda/springcloud-config.git

  1. Create a folder for the local repository
  2. Go to the folder, right-click it, and use Git toolsgit clone [email protected]:asfasfasda/springcloud-config.gitDownload the remote repository code to the local repository
  3. Results:

Add files to local repository and submit them to remote repository (on code cloud)

  1. newapplication.yml
spring:
    profiles:
        active: dev

---
Spring:
    profiles: dev
    application: 
        name: springcloud-config-dev
        
---
Spring:
    profiles: test
    application: 
        name: springcloud-config-test
Copy the code
  1. Go to the folder we created, right click, and start the Git tool
  2. The inputgit add .To addapplication.yml
  3. The inputgit statusSee if we add it

  1. Enter git commit -m “add application.yml” to commit it to the local repository

  2. Enter Git push Origin Master to submit it to the code cloud

Where Origin represents the current user and master represents the master branch submitted to the remote repository of the code cloud

  1. Refresh our repository hosted in the code cloud to see if the commit is successful.

8.Git submit error :Updates were rejected because the tip of your current branch is behind

Config

Introduction to the

The Spring Cloud Config project is a configuration management solution for distributed systems. It consists of a Client and a Server. The Server stores the configuration file and provides the content of the configuration file in the form of an interface. The Client obtains data through the interface and initializes its application based on the data.

The experimental operation

The service side

  1. Import dependence
  <! -- config does not write version number, default is 2.2.6.
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <! -- web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
Copy the code
  1. Write the configuration and use the remote repository I created in my last blog post
server:
  port: 3344

spring:
  application:
    name: springcloud-config-server
  The uri is the HTTP address in the remote repository
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/asfasfasda/springcloud-config.git
Copy the code
  1. Write the main startup class@enableconFigServer Annotation to enable server configuration support
package springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

@SpringBootApplication
@EnableConfigServer// Enable server configuration support
public class springcloud_config_server3344 {
    public static void main(String[] args) { SpringApplication.run(springcloud_config_server3344.class,args); }}Copy the code
  1. Start the test

The url to access is as follows:

Where, label: branch in the remote repository profile: application.yml

  • /{application}/{profile}[/{label}]
  • /{application}-{profile}.yml
  • /{label}/{application}-{profile}.yml
  • /{application}-{profile}.properties
  • /{label}/{application}-{profile}.properties

The client

  1. Create another oneconfig-client.ymlFile and upload to remote repository
spring:
 profiles:
  active: dev

---
server:
 port: 8201
# spring configuration
spring:
 profiles: dev
 application: 
  name: springcloud-provider-dev
# eureka configuration
eureka:
 client:
  service-url:
   defaultZone: http://eureka7001:7001/eureka/

---
server:
 port: 8202
# spring configuration
spring:
 profiles: test
 application: 
  name: springcloud-provider-test
# eureka configuration
eureka:
 client:
  service-url:
   defaultZone: http://eureka7001:7001/eureka/
Copy the code
  1. Import dependence
        <! --config-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <! -- web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
Copy the code
  1. Write aplication. Yml configuration
# user-level configuration
spring:
  application:
    name: springcloud-config-client
Copy the code
  1. Write the bootstrap.yml configuration
System-level configuration
spring:
  cloud:
    config:
      name: config-client Yml = config-client.yml = config-client.yml = config-client.yml = config-client.yml = config-client.yml
      profile: dev
      label: master
      uri: http://localhost:3344
Copy the code
  • Bootstrap. yml: system-level configuration
  • Aplication. Yml: user – level configuration
  1. Write controllers that return information retrieved from remote repositories
package springcloud.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class configController {
    @Value("${spring.application.name}")
    private String applicationName;

    @Value("${eureka.client.service-url.defaultZone}")
    private String eurekaServer;

    @Value("${server.port}")
    private String port;

    @RequestMapping("/config")
    public String getConfig(a){
        return "applicationName:"+applicationName+"\n"
                +"eurekaServer:"+eurekaServer+"\n"
                +"port:"+port;
    }

    @RequestMapping("/a")
    public String get(a){
        return "aaa"; }}Copy the code
  1. Write the main startup class
package springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class config_client3355 {
    public static void main(String[] args) { SpringApplication.run(config_client3355.class,args); }}Copy the code
  1. Start the test