Git tools
Download: git-scm.com/download/wi…
After downloading, configure the user name and email
- The input
git config --list
Displays the current Config configuration
- The user name and mailbox are not configured
- The input
git config --global user.name "suisuinian"
Configuring a User Name - The input
git config --global user.email "[email protected]"
Configure your email - Input again
git config --list
Displays the current Config configuration
- The user name and mailbox have been configured
Use code cloud for code hosting
- Register a code cloud account first
- Get the SSH public key (using Git tools)
- The input
ssh-keygen -t rsa -C "[email protected]"
- Press Enter three times to get the public key
- The input
cat ~/.ssh/id_rsa.pub
Look at the public key
- The input
- 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
- Get the SSH address of the remote repository you created
[email protected]:asfasfasda/springcloud-config.git
- Create a folder for the local repository
- Go to the folder, right-click it, and use Git tools
git clone [email protected]:asfasfasda/springcloud-config.git
Download the remote repository code to the local repository - Results:
Add files to local repository and submit them to remote repository (on code cloud)
- new
application.yml
spring:
profiles:
active: dev
---
Spring:
profiles: dev
application:
name: springcloud-config-dev
---
Spring:
profiles: test
application:
name: springcloud-config-test
Copy the code
- Go to the folder we created, right click, and start the Git tool
- The input
git add .
To addapplication.yml
- The input
git status
See if we add it
-
Enter git commit -m “add application.yml” to commit it to the local repository
-
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
- 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
- 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
- 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
- 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
- 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
- Create another one
config-client.yml
File 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
- 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
- Write aplication. Yml configuration
# user-level configuration
spring:
application:
name: springcloud-config-client
Copy the code
- 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
- 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
- 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
- Start the test