Spring Boot应用程序中的特定于环境的application.properties文件

编程入门 行业动态 更新时间:2024-10-28 09:25:48
本文介绍了Spring Boot应用程序中的特定于环境的application.properties文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的Spring Boot应用程序中,我想创建特定于环境的属性文件.我在战争中应用程序的包装类型,我正在嵌入式tomcat中执行它.我使用sts并从sts本身执行main.

In my Spring Boot application, i want to create environment specific properties file. The packaging type of my application in war and i am executing it in embedded tomcat. I use sts and execute the main from sts itself.

  • 我可以拥有特定于环境的属性文件,例如application-$ {env-value} .properties吗?
  • 在上述情况下,env-value的值将为local/devl/test/prod

    In above case, env-value will have values as local/devl/test/prod

  • 在哪里设置环境值文件?对于本地,我可以通过sts

  • Where to set the env-value file? For local, i can set it as the jvm argument through sts

    谁在Spring Boot应用程序中读取application.properties.

    Who reads the application.properties in Spring Boot application.

    如何加载特定于环境的属性文件?例如-如果我在特定于环境的属性文件中设置数据库uid,pwd,schema等,那么在这种情况下,数据源将能够理解其中的属性?

    How to load the environment specific properties file? For ex - if i set the database uid,pwd, schema etc in environment specific property file, in that case will the datasource be able to understand the properties in it?

    我可以同时使用application.properties和application-local.properties文件吗?

    Can i use application.properties and application-local.properties file at same time?

    推荐答案

    Spring Boot已经已获得支持 基于配置文件的属性.

    Spring Boot already has support for profile based properties.

    只需添加application-[profile].properties文件,然后使用spring.profiles.active属性指定要使用的配置文件.

    Simply add an application-[profile].properties file and specify the profiles to use using the spring.profiles.active property.

    -Dspring.profiles.active=local

    这将从application.properties和application-local.properties的第一个优先属性中加载后者.

    This will load the application.properties and the application-local.properties with the latter overriding properties from the first.

  • 更多推荐

    Spring Boot应用程序中的特定于环境的application.properties文件

    本文发布于:2023-11-14 02:05:19,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1585931.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:应用程序   环境   文件   Boot   Spring

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!