spring boot cloud 远程配置GITHUB
时间: 2023-11-16 08:07:31 浏览: 50
Spring Boot Cloud 远程配置可以使用 GitHub 存储配置文件,以便在不同的环境中使用相同的配置。以下是如何在 Spring Boot Cloud 中使用 GitHub 存储配置文件的步骤:
1. 在 GitHub 上创建一个仓库,并在仓库中创建一个名为 `application.yml` 的配置文件,内容如下:
```
server:
port: 8080
spring:
datasource:
url: jdbc:mysql://localhost:3306/mydb
username: myuser
password: mypassword
```
2. 在 Spring Boot 项目的 `src/main/resources` 目录中创建一个名为 `bootstrap.yml` 的配置文件,内容如下:
```
spring:
cloud:
config:
uri: https://github.com/your-github-username/your-github-repo/
username: your-github-username
password: your-github-password
profile: dev
```
其中,`uri` 指定了 GitHub 仓库的 URL,`username` 和 `password` 是 GitHub 的用户名和密码,`profile` 指定了要使用的配置文件的环境。
3. 在 Spring Boot 项目中添加以下 Maven 依赖:
```
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
```
4. 在 Spring Boot 项目的启动类上添加 `@EnableConfigServer` 注解:
```
@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
```
5. 启动 Spring Boot 项目,访问 `http://localhost:8080/application/dev` 可以看到 GitHub 上的配置文件已被加载。
以上就是使用 GitHub 存储配置文件的 Spring Boot Cloud 远程配置的步骤。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)