我有一个应用程序,我可以为其指定运行它的配置文件。 但我也想将这些配置文件分组为凭证、应用程序性能、内存打印、应用程序行为等。 前任。我可以运行以下配置文件
-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
组,其中包含我们的 proddb
和 prodmq
配置文件。
这允许定义一个分组,该分组被添加到 spring-profiles-active 中,当启用时,它又会启用其他配置文件。
关于java - Spring 轮廓组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14731979/