好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

springboot中的多个application文件讲解

springboot 多个 application 文件

生产部署的配置和测试的配置往往是不一样的,如果都是在一个application.properties文件中修改,不但容易出现遗漏,而且反反复复很是麻烦。

如果采用springboot的profiles来区分生产和测试,那么可以减少许多不必要的工作,需要修改的配置往往就是一两句

1、创建生产和测试文件如下

2、application.properties配置如下

注:

1、spring.profiles.active是用来激活springboot多文件配置的; 在springboot中多环境配置文件名需要满足application-xxx.properties的命名规则; 其中的xxx正是我们spring.profiles.active需要指定的配置文件名 2、想使用哪个配置,修改application.properties主配置文件的spring.profiles.active标签 3、加载多个配置文件spring.profiles.active = xxx,xxx

例如:spring.profiles.active = test,database

 

springboot拆分application.yml为多个

就像这样

application-{}.yml

在application.yml指定当前运行的环境

spring:
profiles:
  active: dev

然后可以在不同的环境设置不同的数据库

如:

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

原文链接:https://blog.csdn.net/qq_42714869/article/details/83030097

查看更多关于springboot中的多个application文件讲解的详细内容...

  阅读:43次