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.

Injecting @ConfigProperty(name="quarkus.servlet.context-path") does not work in native mode

See original GitHub issue

Describe the bug

@ConfigProperty works to inject quarkus.servlet.context-path into a field in JVM mode, but apparently not in native mode, or least not in tests.

Expected behavior

Behavior should be identical across @QuarkusTest and @SubstrateTest.

Actual behavior

Injection works as expected in JVM mode (surefire:test). Native tests (failsafe:integration-test) fail with Unable to start native image in 60s from NativeImageLauncher.waitForQuarkus after

Executing [/project/target/…-1.0-SNAPSHOT-runner, -Dquarkus.http.port=8091, -Dtest.url=http://localhost:8091, -Dquarkus.log.file.path=target/quarkus.log, -Dkubernetes.trust.certificates=true, -Dkubernetes.auth.tryServiceAccount=false, -Dkubernetes.master=http://localhost:39499/, -Dkubernetes.auth.tryKubeConfig=false, -Dkubernetes.namespace=test]
 javax.enterprise.inject.spi.DeploymentException: No config value of type [java.lang.String] exists for: quarkus.servlet.context-path
 	at io.quarkus.arc.runtime.ConfigRecorder.validateConfigProperties(ConfigRecorder.java:37)
 	at io.quarkus.deployment.steps.ConfigBuildStep$validateConfigProperties15.deploy_0(ConfigBuildStep$validateConfigProperties15.zig:120)
 	at io.quarkus.deployment.steps.ConfigBuildStep$validateConfigProperties15.deploy(ConfigBuildStep$validateConfigProperties15.zig:36)
 	at io.quarkus.runner.ApplicationImpl1.doStart(ApplicationImpl1.zig:147)
 	at io.quarkus.runtime.Application.start(Application.java:91)
 	at io.quarkus.runtime.Application.run(Application.java:204)
 	at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:34)
 Exception in thread "main" java.lang.RuntimeException: Failed to start quarkus
 	at io.quarkus.runner.ApplicationImpl1.doStart(ApplicationImpl1.zig:191)
 	at io.quarkus.runtime.Application.start(Application.java:91)
 	at io.quarkus.runtime.Application.run(Application.java:204)
 	at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:34)
 Caused by: javax.enterprise.inject.spi.DeploymentException: No config value of type [java.lang.String] exists for: quarkus.servlet.context-path
 	at io.quarkus.arc.runtime.ConfigRecorder.validateConfigProperties(ConfigRecorder.java:37)
 	at io.quarkus.deployment.steps.ConfigBuildStep$validateConfigProperties15.deploy_0(ConfigBuildStep$validateConfigProperties15.zig:120)
 	at io.quarkus.deployment.steps.ConfigBuildStep$validateConfigProperties15.deploy(ConfigBuildStep$validateConfigProperties15.zig:36)
 	at io.quarkus.runner.ApplicationImpl1.doStart(ApplicationImpl1.zig:147)
 	... 3 more

To Reproduce

Do not have a minimal public demo currently available. One resource had

@Inject KubernetesClient k8sClient;
@ConfigProperty(name = "quarkus.servlet.context-path") String contextPath;

Configuration

quarkus.http.port=8090
quarkus.http.test-port=8091
quarkus.servlet.context-path=/something

Screenshots

N/A

Environment (please complete the following information):

  • Output of uname -a or ver: N/A (Dockerized environment)
  • Output of java -version: N/A; using quay.io/quarkus/centos-quarkus-maven:19.2.0
  • GraalVM version (if different from Java): ditto
  • Quarkus version or git rev: 0.21.2

Additional context

Workaround: hardcode the context path in the source file, and rely on test coverage to catch mismatches with the actual value.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dmlloydcommented, Sep 5, 2019

Right, at present I believe that BUILD_TIME config root values are not stored in the run time image. However, perhaps that should change: even if the config objects themselves are not available at run time, there’s probably no harm in making those properties available to those using the config API directly. The only cost would be the memory usage of the additional keys and values.

What will be the difference with BUILD_AND_RUN_TIME_FIXED ?

The difference would be that the configuration root classes and corresponding groups and objects would not exist in the run time image.

0reactions
johnpothcommented, Nov 22, 2019

I ran into the same problem regarding application specific properties.

As a workaround I used the ConfigProvider.getConfig().getOptionalValue API which works in both @QuarkusTest and @SubstrateTest.

Thanks !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Home of Quarkus Cheat-Sheet - GitHub Pages
Quarkus is a Kubernetes Native Java stack tailored for GraalVM & OpenJDK HotSpot, ... context-path ... This does not work when using native...
Read more >
Quarkus Cheat-Sheet - PDFCOFFEE.COM
If property does not follow getter/setter naming convention you need to use org.eclipse.microprofile.config.inject.ConfigProperty to set it.
Read more >
Java | Programmatic Ponderings
The Spring Boot service was running three Kubernetes pod replicas on Amazon EKS in the AWS US East (N. Virginia) Region. Sample of...
Read more >
Quarkus Cheat Sheet | PDF | Application Programming Interface
Quarkus. Cheat-Sheet. What is Quarkus? Or in Kotlin: @ConfigProperty(name = "greetings.message"). String message; Quarkus is a Kubernetes Native Java stack ...
Read more >
Quarkus Cheat-Sheet - Docslib.org
Or in Kotlin: Command mode Quarkus is a Kubernetes Native Java stack tailored for ... in the same le @ConfigProperty(name = "quarkus.application.name") ...
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