java - Spring Boot 和配置文件

标签 java spring spring-boot

我有一个带有一些配置的 Spring Boot 应用程序。 我想为 devproduction 指定不同的配置值。 我的 application.properties 文件如下所示:

spring.datasource.url=jdbc:mysql://devhost:devport/devschema
spring.datasource.username=devuser
spring.datasource.password=mypwd
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

此文件位于我在 Openshift 上的 git 存储库中。每次提交时,Openshift 都会开始部署应用程序,因此我需要具有正确值的 application.properties。 是否可以使用配置文件之类的东西来更改配置?

最佳答案

您可以使用 spring.profiles.active Spring 属性来选择要使用的application-[environment].properties 文件。然后创建多个文件,每个环境一个。要设置环境,只需在您的 Java 参数中传递此 --spring.profiles.active=development

关于java - Spring Boot 和配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35815394/

相关文章:

java - 返回错误的凭据并返回 getAuthenticationManager().authenticate()

java - @JsonSerialize 没有从 Controller springboot 2.2.4 转换我的日期格式

Azure Pipeline - 目标版本无效 : 11

java - Spring in Practice 书第 1 章中关于单例 bean 不维护状态所需的揭秘

java - Spring Boot : Use database and application. 配置属性

spring-boot - Resttemplate 和补丁,无效

java - 当我尝试在 fragment 生命周期中实例化新类时出错

java - 根据用户提示延长 session

java - 声明字符串对象的混淆

java - 使用 Spring AMQP 自动恢复 AMQP 连接期间的 AlreadyClosedException