Skip to content

How to load sub yml config file use spring.profiles.group property? #24309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
blling opened this issue Dec 2, 2020 · 7 comments
Closed

How to load sub yml config file use spring.profiles.group property? #24309

blling opened this issue Dec 2, 2020 · 7 comments
Labels
for: stackoverflow A question that's better suited to stackoverflow.com

Comments

@blling
Copy link

blling commented Dec 2, 2020

Spring-Boot Version: 2.4.0

When migrate from spring.profiles.include to spring.profiles.group, Spring-Boot no longer load sub yml configs from the classpath.

application.yml

spring:
  profiles:
    group:
      - base-db
      - base-quartz
      - base-app

main resource:
image

application-test.yml

spring:
  profiles:
    group:
      - test-db
      - test-quartz
      - test-app

test resource:
image

log shows Spring-Boot only load application.yml and application-test.yml, but no base-db, base-quartz, base-app,test-db, test-quartz, test-app

2020-12-02 13:22:07.463 TRACE  [main] org.springframework.boot.context.config.ConfigDataEnvironment Adding imported property source 'Config resource 'classpath:/application-test.yml' via location 'optional:classpath:/''
2020-12-02 13:22:07.463 TRACE  [main] org.springframework.boot.context.config.ConfigDataEnvironment Adding imported property source 'Config resource 'classpath:/application.yml' via location 'optional:classpath:/''

If run with --spring.profiles.active=test, Spring-Boot should also load base-db, base-quartz, base-app,test-db, test-quartz, test-app too, am i right?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 2, 2020
@philwebb
Copy link
Member

philwebb commented Dec 2, 2020

You need to include the source profile as part of the group property (see https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-profiles-groups). For example:

spring:
  profiles:
    group:
      test:
      - test-db
      - test-quartz
      - test-app

For the base- profiles you probably want the following since they're always active:

spring:
  profiles:
    include:
    - base-db
    - base-quartz
    - base-app

@philwebb philwebb closed this as completed Dec 2, 2020
@philwebb philwebb added for: stackoverflow A question that's better suited to stackoverflow.com and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 2, 2020
@blling
Copy link
Author

blling commented Dec 2, 2020

Thanks,how does test-* inherit base-*?
For example, i need test-app inherit base-app to change a property value in the base-app,then what is the the config looks like?

@philwebb
Copy link
Member

philwebb commented Dec 3, 2020

I think the example I included should so that. If not, please ask the question on stackoverflow.com with a small sample app. If you post a link to the question here, I'll try to answer it on stackoverflow. We prefer to keep the issue tracker just for bugs.

@blling
Copy link
Author

blling commented Dec 3, 2020

@philwebb Thinks!
Finally, application-test.yml worked use the config as follows:

spring:
  profiles:
    group:
      test:
        - base-app
        - base-db
        - base-quartz
      base-app: test-app
      base-db: test-db
      base-quartz: test-quartz

The inheritance relationship on the configuration looks a bit strange, but it works.

BTW. The follow configuration should not work:

spring:
  profiles:
    group:
      test:
        - test-app
        - test-db
        - test-quartz
      test-app: base-app
      test-db: base-db
      test-quartz: base-quartz

Because, by this way, the base-* properties will cover the test-*, but i want test-* cover base-* :-( . I do not know if this is a expected design, but it looks really strange.

@blling
Copy link
Author

blling commented Dec 11, 2020

Ref: #24172

@vignesh-ragavan
Copy link

vignesh-ragavan commented Aug 31, 2022

How to run the application using group name?
-Dspring.profile.active=groupname @philwebb

@wilkinsona
Copy link
Member

@vignesh-ragavan As Phil said above, please ask questions on Stack Overflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com
Projects
None yet
Development

No branches or pull requests

5 participants