quarkus: bootstrap config with field does not pick up QUARKUS_CONFIG_LOCATIONS files
Describe the bug
If I define a property in a file referenced by QUARKUS_CONFIG_LOCATIONS , it will not be picked up if part of a config object with phase BOOTSTRAP
. it works fine with RUN_TIME
.
Expected behavior
The value should be taken into account as if it was defined in the classpath’s application.properties.
Actual behavior
The value is ignored.
How to Reproduce?
Define the following config object in an extension:
@ConfigRoot(name = "hello", phase = ConfigPhase.BOOTSTRAP)
public class HelloConfig {
/**
* doc
*/
@ConfigItem(name = "map")
public Map<String, MapConfig> map;
@Override
public String toString() {
return "HelloConfig{" + "map=" + map + '}';
}
@ConfigGroup
public static class MapConfig {
/**
* doc
*/
@ConfigItem(name = ConfigItem.PARENT)
String value;
public MapConfig(String value) {
this.value = value;
}
public MapConfig() {
value = "";
}
@Override
public String toString() {
return "MapConfig{" + "value=" + value + '}';
}
}
}
Create a recorder:
@Recorder
public class HelloRecorder {
private final HelloConfig config;
public HelloRecorder(HelloConfig config) {
this.config = config;
}
public void sayHello(String name) {
System.out.println("==> Hello" + name+" with config " + config);
}
}
And a build step:
@Record(ExecutionTime.RUNTIME_INIT)
@BuildStep
public void helloBuildStep(HelloRecorder recorder) {
recorder.sayHello("World");
}
In the src/main/resources/application.yaml:
quarkus:
hello:
map:
mytest: foo
In a directory create a .env with:
QUARKUS_CONFIG_LOCATIONS=base-application.properties
And create base-application.properties
with:
# ordinal between application.properties in classpath (250) and ./config/application.properties (260)
config_ordinal=255
quarkus.hello.map.mytest=bar
Compile and start the application:
$ java -jar ../target/quarkus-app/quarkus-run.jar
==> HelloWorld with config HelloConfig{map={mytest=MapConfig{value=foo}}}
The value foo
comes from the src/main/resources/application.yaml
, which means the base-application.properties
has been ignored.
Now change the config phase to RUN_TIME
:
@ConfigRoot(name = "hello", phase = ConfigPhase.RUN_TIME)
public class HelloConfig {
Compile and relaunch:
$ java -jar ../target/quarkus-app/quarkus-run.jar
==> HelloWorld with config HelloConfig{map={mytest=MapConfig{value=bar}}}
Now the bar
value is correctly picked up.
I have tried also with a normal field (i.e. not a Map
), and the behavior is the same. So it is essentially related to boostrap config vs runtime.
May also be related to https://github.com/quarkusio/quarkus/issues/24463 see https://quarkusio.zulipchat.com/#narrow/stream/294206-smallrye/topic/Map.20config.20env.20variable.20override cc @radcortez
Output of uname -a
or ver
MINGW64_NT-10.0-19042 DEVPC028554 3.1.4-340.x86_64 2020-05-19 12:55 UTC x86_64 Msys
Output of java -version
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.7.3.Final
Build tool (ie. output of mvnw --version
or gradlew --version
)
Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)
Additional information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (15 by maintainers)
The fix was missing a piece. Unfortunately, the test that I wrote didn’t take into account config recording from build time so it seemed to be working.
Can you try it with https://github.com/quarkusio/quarkus/pull/25351? Thanks!