ymal中引入其他的yml或properties

在开发过程中如果需要其他的配置文件,全部写到application.yml中感觉太臃肿,这时,我们可以将yml拆分成多个yml或者properties文件 在配置文件目录(如:resources)下新建application-xx开头...

在开发过程中如果需要其他的配置文件,全部写到application.yml中感觉太臃肿,这时,我们可以将yml拆分成多个yml或者properties文件

  • 在配置文件目录(如:resources)下新建application-xx开头的properties或者yml文件
  application-test.yml
  application-prod.yml
  application-dev.yml
  • 然后再在application.yml中添加配置
  spring:
    profiles:
        include:
            test,api,jdbc

注意,不能换行,include:下面的test,api,jdbc,多个用英文逗号分隔

  • 然后在程序中就同时可以访问test,prod,dev中的东西了
  @Value('${qq.key}')
  private String qq

  @Value('${weixin.key}')
  private String weixin

  @Value('${a.b.c}')
  private String t

  @Value('${aa.bb}')
  private String tt
  • 发表于 2018-09-27 18:13
  • 阅读 ( 3189 )
  • 分类:springboot

1 条评论

请先 登录 后评论
不写代码的码农
Jonny

程序猿

65 篇文章

作家榜 »

  1. 威猛的小站长 124 文章
  2. Jonny 65 文章
  3. 江南烟雨 36 文章
  4. - Nightmare 33 文章
  5. doublechina 31 文章
  6. HJ社区-肖峰 29 文章
  7. 伪摄影 22 文章
  8. Alan 14 文章