-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Microprofile Config doesn't read config profiled properties when injected into servlet.Filter class in native mode #23807
Comments
Shouldn't be necessary.
It's complicated, but this should work. |
@pbezpalko any chance you could put together a sample application that exhibits the problematic behavior? |
Hi @geoand - yes, I will try to prepare the simplest application demonstrating all the problems found. I hope to be able to do this later this week. |
Hi @geoand - I prepare simple demo for this bug - can be found here: There is README.md with detailed information how to build and run. The bug is quite visible :) |
Looks like one for @radcortez |
I'll have a look. |
This is a very interesting case. Let me see if I can explain what is happening properly: The filters are initialized during the native image build, so the config instance that gets injected is also one that is created during static initialization, which uses the profile set during the native image build (if omitted is In the other case with the helper, the filter is also initialized during the native image build time and the injection point gets a lazy reference that is only created when required (when the app is called for the first time). In this case, the config instance you get is one that is created during runtime which uses the profile set by the user in the command line. One way to fix this is to wrap your But this raises some additional questions:
|
Logging a warning sounds like a good idea to me |
Well, it's a known issue but I have no idea how to detect these cases...
Yes, a general workaround is to fetch the config lazily at runtime. You can do the same with |
Describe the bug
It seems to quarkus-undertow (processing Filter classes) doesn't work properly with profiled Quarkus configuration under native image.
Injected org.eclipse.microprofile.config.Config instance in class implementing javax.servlet.Filter doesn't contain values defined in active profile. But this happens only in native mode. Under standard JVM everything works fine and all variables (core + profiled) are available.
Filter class:
Configuration file:
Run under JVM:
java -jar ... -Dquarkus.profile=NONE-CI....
Run under Native:
./application -Dquarkus.profile=NONE-CI
Expected behavior
For both, native and standard jvm, execution of config.getOptionalValue("stage.environment") returns the same value if the same profile will be used.
Actual behavior
config.getOptionalValue("stage.environment") works invalid when application is started under native mode and returns empty Optional object.
config.getOptionalValue("stage.environment") works properly when application is started under standard JVM mode and returns value "CI" - which is perfectly OK.
My working Workaround:
How to Reproduce?
No response
Output of
uname -a
orver
Microsoft Windows [Version 10.0.19042.1466] / Native run under Docker image based on registry.access.redhat.com/ubi8/ubi-minimal:8.4
Output of
java -version
OpenJDK Runtime Environment Corretto-11.0.7.10.1 (build 11.0.7+10-LTS)
GraalVM version (if different from Java)
quarkus-mandrel:21.3-java11
Quarkus version or git rev
2.5.0.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00) Java version: 11.0.7, vendor: Amazon.com Inc., runtime: C:\Programs\jdk-11-amazoncorretto Default locale: en_US, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
Additional information
Application compile & build:
I verified this also in servlet class (extends javax.servlet.http.HttpServlet). In this case all works properly and variables are read correctly both from directly injected Config instance and indirectly injected via Helper (application scoped) class.
The text was updated successfully, but these errors were encountered: