Spring Boot基础学习笔记05:Spring Boot多环境配置

(一)创建Spring Boot Web项目ProfileDemo01
在这里插入图片描述
(二)创建多环境配置文件
1、将application.properties更名为application.yaml
在这里插入图片描述

2、模拟开发环境,创建配置文件application-dev.yaml

在这里插入图片描述

3、模拟测试环境,创建配置文件application-test.yaml

在这里插入图片描述

4、模拟生产环境,创建配置文件application-pro.yaml

在这里插入图片描述

(三)创建控制器

在这里插入图片描述
package net.hw.lesson05.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProfileController {
@GetMapping("/hello")
public String hello() {
return “Welcome to Spring Boot World~”;
}
}

(四)指定使用环境

(1) 在全局配置文件里指定当前使用环境 - 开发环境
在这里插入图片描述

  • 启动项目,查看采用的使用环境:服务器端口号与虚拟路径
    在这里插入图片描述
  • 访问http://localhost:8081/lzy/hello
    在这里插入图片描述
    (2) 在全局配置文件里指定当前使用环境 - 测试环境
    在这里插入图片描述
  • 启动项目,查看采用的使用环境:服务器端口号与虚拟路径
    在这里插入图片描述
    访问http://localhost:8081/lzy/hello
    在这里插入图片描述
    访问http://localhost:8082/ied/hello
    在这里插入图片描述

(3) 在全局配置文件里指定当前使用环境 - 生产环境

在这里插入图片描述
启动项目,查看采用的使用环境:服务器端口号与虚拟路径
在这里插入图片描述

  • 访问http://localhost:8082/ied/hello
  • 在这里插入图片描述
  • 访问http://localhost:8083/china/hello
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值