question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing config files across modules

See original GitHub issue

I have two modules in the same project, one by another:

A
|-- application.yaml
|-- application-dev.yaml

B
|-- base-application.yaml
|-- base-application-dev.yaml

Been using custom EnvironmentPostProcessor to load base- config into A but with SB 2.4 I wanted to give config.import a try. But there are a few issues arisen.

(1) In A/application.yaml I’ve added the following:

spring:
  config:
    import: classpath:/base-application.yaml

In A/application-dev.yaml it’s respectively:

spring:
  config:
    import: classpath:/base-application-dev.yaml

Trying to start A fails with Config data location 'classpath:/base-application-dev.yaml' does not exist. That’s rather confusing considering that it does exist indeed and that classpath:/base-application.yaml is loaded just fine from the same location. To verify that, I made a typo in the file name and it failed for 'classpath:/bas-application.yaml' as expected.

Renaming base-application-dev.yaml to something profile-unrelated like some-file.yaml still fails with resource does not exist.

(2) If I don’t change A/application-dev.yaml at all, I do see that SB takes B/base-application-dev.yaml into account when loading classpath:/base-application.yaml and properly loads it. The application starts just fine with all properties. So clearly it does exist in (1). But now the ordering of property sources is not correct. Here’s what it is from environment:

...
application-dev.yaml
base-application-dev.yaml
base-application.yaml
application.yaml
...

base-dev overrides dev but application overrides base-application.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
scottfrederickcommented, Apr 16, 2021

As you said initially, there are a few issues here.

One is a bug that’s causing a confusing error message unrelated to modules and precedence of property loading. I’ve now split that out into #26147 so we can address that bug.

The rest of this discussion has to do with a specific problem you are trying to solve and whether your approach will work given the design of Spring Boot’s property loading. Let’s continue that discussion here.

0reactions
edudarcommented, Apr 21, 2021

What order do we load the resources and how do we make sure a developer can override a contributed value

Yeah, that’s an ultimate question in the late discussion here. I’ll close this one then as there are two tickets that cover it now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python ConfigParser - usage across modules - Stack Overflow
Then other modules get access to it in the following way: from configmodule import config config.get(spam, eggs).
Read more >
Python - Share global variables across modules from user ...
My program takes a yaml config file as parameter python myprogram.py cfg.yml . all modules can access the cfg content with a simple...
Read more >
How do I share global variables across modules - python
The best way to share global variables across modules across a single program is to create a config module. Just import the config...
Read more >
Tips and Tricks for Handling Configuration Files in Python
This tutorial focuses on a Python module called ConfigParser. ... A configuration file consists of one or multiple sections identified based ...
Read more >
ConfigParser – Work with configuration files - PyMOTW
Use the ConfigParser module to manage user-editable configuration files for an application. The configuration files are organized into sections, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found