将 application.yml 文件转换为 application.properties

Sud*_*ini 9 java spring-boot netflix-eureka application.properties

我的 application.yml 文件如下。如何将其转换为 application.properties 我正在尝试,但如何在同一个文件中写入多个属性。它给了我重复的克里错误。

 ---
  spring:
    profiles: peer1
  eureka:
     instance:
        hostname: peer1
     client:
        serviceUrl:
           defaultZone: http://peer2/eureka/

 ---
 spring:
    profiles: peer2
 eureka:
    instance:
      hostname: peer2
    client:
      serviceUrl:
         defaultZone: http://peer1/eureka/
Run Code Online (Sandbox Code Playgroud)

小智 6

IntelliJ 和其他 IDE 也提供了相同的插件。

例如- https://plugins.jetbrains.com/plugin/13804-convert-yaml-and-properties-file

安装插件,右键单击您的 yaml 或属性文件,然后选择 - “转换 yaml 和属性文件”。


M.R*_*uti 0

使用属性文件时,同一文件中的每个配置文件不能有多个“部分”,此功能仅适用于 Yaml。您必须创建多个属性文件,每个配置文件一个,如下所述:https ://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html#howto -根据环境更改配置

要对属性文件执行相同的操作,您可以使用 application-${profile}.properties 指定特定于配置文件的值

您将拥有一个包含常用值的主 application.properties 文件,然后每个配置文件都有一个 application-${profile}.properties 文件,其中包含与环境/配置文件相关的值。

最后,您必须在运行应用程序时将活动配置文件设置为系统属性,或者直接在主 application.properties 文件中设置,如下所述: https: //docs.spring.io/spring-boot/docs/当前/reference/html/howto-properties-and-configuration.html#howto-set-active-spring-profiles