一、环境

1.1、Idea 2020.1

1.2、JDK 1.8

二、目的

通过yaml文件配置spring boot 属性文件

三、步骤

3.1、点击File -> New Project -> Spring Initializer,点击next

3.2、在对应地方修改自己的项目信息

3.3、选择Web依赖,选中Spring Web。可以选择Spring Boot版本,本次默认为2.2.6,点击Next

3.4、编辑工程名和项目路径,确定后点击Finish完成

3.5、项目结构

四、添加测试文件

package org.ouyushan.springboot.profile;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment; @SpringBootApplication
public class SpringBootProfileApplication { public static void main(String[] args) {
ConfigurableApplicationContext applicationContext = SpringApplication.run(SpringBootProfileApplication.class, args);
ConfigurableEnvironment environment = applicationContext.getEnvironment();
System.out.println("server.port:" + environment.getProperty("server.port"));
} } 

4.1、配置默认application.yaml

spring:
profiles:
active: dat
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: Asia/Chongqing

4.2、配置application-dat.yaml

server:
port: 7070

4.3、配置application-uat.yaml

server:
port: 8080

4.4、配置application-vir.yaml

server:
port: 9090
启动项目,通过修改 application.yaml中的spring.profiles.active属性值来判断激活环境

五、知识点

一般将公共属性配置在application.yaml中,与环境相关的属性配置在对应的配置中,只需在application.yaml中配置
spring:
profiles:
active: uat

Spring boot Sample 005之spring-boot-profile的更多相关文章

  1. Spring boot Sample 012之spring-boot-web-upload

    一.环境 1.1.Idea 2020.1 1.2.JDK 1.8 二.目的 spring boot 整合web实现文件上传下载 三.步骤 3.1.点击File -> New Project -& ...

  2. Spring boot Sample 0010之spring-boot-web-freemarker

    一.环境 1.1.Idea 2020.1 1.2.JDK 1.8 二.目的 spring boot 整合freemarker模板开发web项目 三.步骤 3.1.点击File -> New Pr ...

  3. Spring boot Sample 009之spring-boot-web-thymeleaf

    一.环境 1.1.Idea 2020.1 1.2.JDK 1.8 二.目的 spring boot 整合thymeleaf模板开发web项目 三.步骤 3.1.点击File -> New Pro ...

  4. Spring boot Sample 006之spring-boot-custom-servlet

    一.环境 1.1.Idea 2020.1 1.2.JDK 1.8 二.步骤 2.1.点击File -> New Project -> Spring Initializer,点击next 2 ...

  5. Spring Boot (五)Spring Data JPA 操作 MySQL 8

    一.Spring Data JPA 介绍 JPA(Java Persistence API)Java持久化API,是 Java 持久化的标准规范,Hibernate是持久化规范的技术实现,而Sprin ...

  6. 初入spring boot(七 )Spring Data JPA

    Spring Data JPA通过提供基于JPA的Repository极大地减少JPA作为数据访问方案的代码量. 1.定义数据访问层 使用Spring Data JPA建立数据访问层十分简单,只需定义 ...

  7. Spring Boot配置篇(基于Spring Boot 2.0系列)

    1:概述 SpringBoot支持外部化配置,配置文件格式如下所示: properties files yaml files environment variables command-line ar ...

  8. Spring 5.x 、Spring Boot 2.x 、Spring Cloud 与常用技术栈整合

    项目 GitHub 地址:https://github.com/heibaiying/spring-samples-for-all 版本说明: Spring: 5.1.3.RELEASE Spring ...

  9. Spring Boot-初学01 -使用Spring Initializer快速创建Spring Boot项目 -@RestController+spEL -实现简单SpringBoot的Web页面

    1.IDEA:使用 Spring Initializer快速创建项目 IDE都支持使用Spring的项目创建向导快速创建一个Spring Boot项目: 选择我们需要的模块:向导会联网创建Spring ...

随机推荐

  1. H - Buy Tickets POJ - 2828 逆序遍历 树状数组+二分

    H - Buy Tickets POJ - 2828 这个题目还是比较简单的,其实有思路,不过中途又断了,最后写了一发别的想法的T了. 然后脑子就有点糊涂,不应该啊,这个题目应该会写才对,这个和之前的 ...

  2. Python网络爬虫练习

    1. 豆瓣top250电影 1.1 查看网页 目标网址:https://movie.douban.com/top250?start=0&filter= start=后面的数字从0,25,50一 ...

  3. python路径操作新标准:pathlib 模块

    之前如果要使用 python 操作文件路径,我总是会条件反射导入 os.path. 而现在,我会更加喜欢用新式的 pathlib, 虽然用得还是没有 os.path 熟练,但是以后会坚持使用. pat ...

  4. Python求差集

    本月月初在职员工表(20来列,身份证.银行卡号等),本月离职员工表(10来列,计时.计件等),不考虑本月入职员工表,求下月月初在职员工表. Python,import pandas as pd,两个p ...

  5. [hdu5402 Travelling Salesman Problem]YY

    题意:给一个n*m的矩形,每个格子有一个非负数,求一条从(1,1)到(n,m)的路径(不能经过重复的格子),使得经过的数的和最大,输出具体的方案 思路:对于row为奇数的情况,一行行扫下来即可全部走完 ...

  6. springBoot第二种配置文件yaml书写方式及读取数据、整合myBatis和整合junit

    一.yaml文件格式:key-value形式:可以表示对象 集合 1.语法:key:value 冒号后面必须跟一个空格再写value值 key1: key2: key3:value 2.属性取值:a. ...

  7. 容器技术之LXC

    什么是容器?在生活中我们常见的容器有各种瓶瓶罐罐.各种能够容纳其它物料的东西叫容器:容器的特点就是有着很好的隔离作用,使得不同的物料互相隔离:除此之外容器还方便运输.方便储存:这是生活中所说的容器,以 ...

  8. python-修改文件

    1.修改文件1 # fw = open('username','w')# fw.write('hhhh')# fw.flush()  #强制把缓冲区里面的数据写到磁盘上1.简单粗暴直接#  1.打开一 ...

  9. java 生成随机字符串

    1.生成之指定位数的随机字符串 /** * 随机基数 */ private static char[] charset = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h ...

  10. Bash Shell之内建命令和保留字

    转载自:http://blog.chinaunix.net/uid-25880122-id-2941630.html 命令 含义 ! 保留字,逻辑非 : 不做任何事,只做参数展开 . 读取文件并在sh ...