springboot学习总结二(Spring boot的核心配置文件)

Spring boot的核心配置文件

spring boot的核心配置文件用于配置Spring boot程序,有两种格式的配置文件

  1. properties文件--- 键值对的properties属性文件配置方式

       

     2.yml文件

     

     3.多环境配置文件

      #比如配置环境

      application-dev.properties

      application-test.properties

      application-online.properties

     

Spring boot的自定义配置

我们可以在Spring boot的核心配置文件中自定义配置,然后采用如下注解去读取配置的属性值

  1. @Value注解
  2. @ConfigurationProperties

@Value注解方式:

  • 编写自定义文件

       

  • 读取自定义文件

       

@ConfigurationProperties注解方式:

  • 新建一个类:

      

  • 读取自定义文件

      

猜你喜欢

转载自blog.csdn.net/weixin_38282405/article/details/85777207