1. 在 spring boot 中,有两种配置文件,一种是application.properties,另一种是application.yml,两种都可以配置spring boot 项目中的一些变量的定义,参数的设置等。下面来说说两者的区别。

application.properties 配置文件在写的时候要写完整,如:

spring.profiles.active=dev
spring.datasource.data-username=root
spring.datasource.data-password=root

在yml 文件中配置的话,写法如下:

  

spring:
profiles:
active: prod
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/test
username: root
password: root yml 文件在写的时候层次感强,而且少写了代码。所以现在很多人都使用yml配置文件。 2. 在项目中配置多套环境的配置方法。
因为现在一个项目有好多环境,开发环境,测试环境,准生产环境,生产环境,每个环境的参数不同,所以我们就可以把每个环境的参数配置到yml文件中,这样在想用哪个环境的时候只需要在主配置文件中将用的配置文件写上就行如下:
spring:
profiles:
active: prod
这行配置在application.yml 文件中,意思是当前起作用的配置文件是application_prod.yml,其他的配置文件命名为 application_dev.yml,application_bat.yml等。 3. 项目启动的时候也可以设置 Java -jar xxxxxx.jar spring.profiles.actiove=prod 也可以这样启动设置配置文件,但是这只是用于开发和测试。 4. 配置文件数据的读取:
比如我在文件中配置了一个
massage:
data:
name: qibaoyi
我在类中想要获取他 需要这样去写:
@Value("${message.data.name}")
private String name; 后面你取到变量name 的值就是配置文件中配置的值。 5. 大家需要注意一点,配置文件中参数的写法:name: qibaoyi中间是有一个空格的,在IDEA 编译器中它会提醒你的。 6. 增加一个知识点:
开发过程中通过MVN切换环境参数。
大家在打包的时候可以通过mvn -P prod 指定环境参数。但是开发过程中,有MVN提供了profile的配置,我们就可以用他来进行处理。
首相需要增加dev,test,prod的配置。在你的pom文件中。

2. 需要增加一个resources的配置

3. 配置 启动参数项

这样就可以了。但是在过程中 没有操作第二步的话 会报错误

解决方案:增加Resource配置。

转载:

https://www.cnblogs.com/baoyi/p/SpringBoot_YML.html

【转载】SpringBoot yml 配置的更多相关文章

  1. SpringBoot yml 配置

    1. 在 spring boot 中,有两种配置文件,一种是application.properties,另一种是application.yml,两种都可以配置spring boot 项目中的一些变量 ...

  2. SpringBoot yml 配置 多配置文件,开发环境,生产环境配置文件分开

    原文地址:https://www.cnblogs.com/baoyi/p/SpringBoot_YML.html 1. 在 spring boot 中,有两种配置文件,一种是application.p ...

  3. springboot 读取 yml 配置的几种方式

    前言:在springboot 项目中一般默认的配置文件是application.properties,但是实际项目中我们一般会使用application.yml 文件,下面就介绍一下在springbo ...

  4. application.properties /application.yml官网查看配置;springboot application.properties 官网查看,info yml 查看;springboot.yml查看info;springboot.yml查看Actuator监控中心info

    官网查看: https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#appendix 查看info ...

  5. 【转】SpringBoot学习笔记(7) SpringBoot整合Dubbo(使用yml配置)

    http://blog.csdn.net/a67474506/article/details/61640548 Dubbo是什么东西我这里就不详细介绍了,自己可以去谷歌 SpringBoot整合Dub ...

  6. SpringBoot 使用yml配置 mybatis+pagehelper+druid+freemarker实例

    SpringBoot 使用yml配置 mybatis+pagehelper+druid+freemarker实例 这是一个简单的SpringBoot整合实例 这里是项目的结构目录 首先是pom.xml ...

  7. springboot~yml里的自定义配置~续

    之前写了关于读取自定义配置的文章springboot~yml里的自定义配置,而今天主要说一下对复杂配置信息的读取方法,我们简单的配置用@Value注解就可以了,而结构复杂的一般使用@Configura ...

  8. springboot application.yml配置学习

    一.背景 为了更好的使用springboot,所以看一下application.yml配置这块.主要是看数据绑定这块. 主要参考:https://www.hangge.com/blog/cache/d ...

  9. SpringBoot的yml配置

    Spring Boot的yml配置 #开发配置 spring: data: solr: host: http://localhost:6789/solr/mote mvc: view: # 页面默认前 ...

随机推荐

  1. sklearn中的弹性网函数 ElasticNet

    语法:  ElasticNet(self, alpha=1.0, l1_ratio=0.5, fit_intercept=True, normalize=False, precompute=False ...

  2. boost 介绍

    简介: Boost库是一个可移植.提供源代码的C++库,作为标准库的后备,是C++标准化进程的开发引擎之一. Boost库由C++标准委员会库工作组成员发起,其中有些内容有望成为下一代C++标准库内容 ...

  3. tomcat注册成服务

    1>修改"bin\service.bat"文件 服务名:下图中的SERVICE_NAME 服务显示名称:下图中的DISPLAYNAME 服务描述:Description 2& ...

  4. teraflop级、TFLOPS、TOPS

    FLOPS 每秒浮点运算次数,TFLOPS表示每秒万亿(10^12)次浮点计算: TFLOPS是floating point operations per second 每秒所执行的浮点运算次数. 1 ...

  5. Swift_IOS之UIActivityIndicatorView加载齿轮控件

    // // ViewController.swift // helloIOS // // Created by loaderman on 2019/1/25. // Copyright © 2019年 ...

  6. osg fbx 绘制坐标轴、控制模型影藏与显示

    int main() { osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer; osg::ref_ptr< ...

  7. windows 10 enterprize LTSC

    to avtivate the windows 10 enterprize LTSC version, do the following command every 6 months. slmgr - ...

  8. centos6.8 ssh 问题

    xshell用ROOT不能登录 需要把 /etc/ssh/sshd_config 中的端口新建一个 不能用默认的

  9. sudo内容

    [root@bogon ~]# cat /etc/sudoers## Sudoers allows particular users to run various commands as## the ...

  10. HTML滚动时位置固定

    现在显示器一般都是宽屏,网页两端常常会留白. 两边可能会放一些推荐.标签或是导航什么的辅助模块. 现在有的网站页面内容过长时,用户将滚动条向下拉时,拉到一定程度,左右两侧的辅助模块就会固定在指定位置, ...