配置文件不是设别环境的关键。

在下面的例子中,我们将会用到两个配置文件

  • dev
  • prod

缺省的应用程序配置在 application.properties 中。让我们来看下面的例子:

application.properties

basic.value= true
    basic.message= Dynamic Message 
    basic.number= 100

我们想要为 dev 文件自定义 application.properties 属性。我们需要创建一个名为 application-dev.properties 的文件,并且重写我们想要自定义的属性。

application-dev.properties

basic.message: Dynamic Message in DEV

一旦你特定配置了配置文件,你需要在环境中设定一个活动的配置文件。

有多种方法可以做到这一点:

  • 在 VM 参数中使用 Dspring.profiles.active=prod
  • 在 application.properties 中使用 spring.profiles.active=prod