java - Spring 轮廓组

标签 java spring profiles spring-profiles

我有一个应用程序,我可以为其指定运行它的配置文件。 但我也想将这些配置文件分组为凭证、应用程序性能、内存打印、应用程序行为等。 前任。我可以运行以下配置文件

-Dspring.profiles.active=production,cached-local,db-connection-pooled...

但我更愿意将其初始化为

-Dspring.profiles.active=production,super-fast
#the above activates method level caches, db connection pooling etc
#super-fast triggered activation of cached-local, db-connection-pooled profiles

-Dspring.profiles.active=dev,low-footprint
#the above dosent enable caching, or db connection pooling

这可以在不编写任何自定义代码的情况下实现吗 How to set active spring 3.1 environment profile via a properites file and not via an env variable or system property . 即使我可以从属性文件或 spring-xml 配置中加载这些,我也很好。 我在 spring 3.1 上仅使用 xml 配置。

最佳答案

Spring Boot 已经添加了解决这个问题的功能,称为“配置文件组”。配置文件组允许您为相关配置文件组定义逻辑名称。

例如,我们可以创建一个 production 组,其中包含我们的 proddbprodmq 配置文件。

这允许定义一个分组,该分组被添加到 spring-profiles-active 中,当启用时,它又会启用其他配置文件。

有关详细信息,请参阅 https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.profiles.groups

关于java - Spring 轮廓组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14731979/

相关文章:

java - 在一行中增量 X Mod N

java - 无法将 ArrayList<subtype> 转换为 ArrayList<type>

java - 如何从 JPA EntityManager 清除 Hibernate 缓存?

ios - 运行带有分发配置文件的 xcode 项目

plugins - clojure:使用苹果酒时,profiles.clj 在某些项目中没有得到尊重

ios - 阻止 iOS 设备

java - log4j根据登录linux的人创建动态文件名

java - 将 Eclipseproject 包含到其他作为 OSGi 包的项目中

java - 在 Spring 上下文中导入/过滤属性

java - 如何构建一个同时暴露rest和soap服务的Spring Boot jar