spring - 如何从环境变量添加事件的 Spring 配置文件?

标签 spring spring-boot spring-profiles

到目前为止,我在 ~/.bash_profile 中设置以下环境变量:

export SPRING_PROFILES_ACTIVE=local

这设置了我的事件 Spring 配置文件。但现在,我想将本地配置文件添加application.properties中定义的其他配置文件,而不是替换它们。

Spring Boot documentation ,有一个关于添加事件配置文件的部分,但我没有看到任何有关从环境变量添加事件配置文件的内容。

我尝试设置 SPRING_PROFILES_INCLUDE 环境变量,但这没有效果。

如何做到这一点?

P.S.:我使用的是 Spring Boot 1.4.2。

最佳答案

您链接到的文档中的下一句话:

Sometimes it is useful to have profile-specific properties that add to the active profiles rather than replace them. The spring.profiles.include property can be used to unconditionally add active profiles.

因此您可以使用命令行参数启动应用程序:

-Dspring.profiles.include=${SPRING_PROFILES_INCLUDE}

关于spring - 如何从环境变量添加事件的 Spring 配置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40637544/

相关文章:

java - NoSuchBeanDefinitionException : No qualifying bean of type 'javax.servlet.Filter' available

hibernate - 在DAO,服务层架构中使用spring MVC和Hibernate的正确方法是什么

java - 如何在 Junit 测试中更改 Spring 配置文件

spring - 如何激活配置文件作为环境变量

spring - 如何为多个 Spring 应用程序配置文件设置 Tomcat

java - Spring JPA Repository 合并而不是保存

node.js - 登录应用程序后出现 Express Range 错误

java - @Transactional 上的 MySQL 套接字超时行为

java - spring boot - 从过滤器返回 pojo 响应

java - Spring Boot jar 中的 application.properties 文件在哪里?