-
Notifications
You must be signed in to change notification settings - Fork 8
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
resolveEnvironment Issue #1
Comments
@milindbangar79, the For example, the simplest way to have it work as you expect is to specify a @Inject
@Property(resolveEnvironment = true, defaultValue = "${env.abc}")
private String abc; You could also specify a system property named |
Hi Mike, Thanks for the response. Current requirement is to read the data from application.properties file in classpath. We do have a requirement to set the data for password field(s) in POJO to use environment variables. Will the approach be same as mentioned in your response? Kindly let me know. Regards |
@milindbangar79 , yes you could use the same approach that I mentioned. Additionally, you could do something like the example below, provided that your application.properties has an entry named Unfortuately, this library does not (yet) have a default properties file location, like application.properties, so you need to specify it with the POJO: @Inject
@Property(resolveEnvironment = true,
resource = @PropertyResource("classpath:application.properties"))
private String secretPasswordValue; application.properties
|
Hi Mike, Thanks for the quick response. I will try and get back. Regards |
Hi Mark, I tried both the approaches. Approach 1 : The first time calling the service endpoint, I get javax.enterprise.inject.InjectionException. When I call the endpoitn again, it does not give the exception. This behaviour I have observed while trying to set the values of class variables for which some are being resolved through application.properties and few through environment variables. Approach 2: It's not working as expected and getting NullPointerException on the field in application.properties file used in code. Kindly help. Regards |
Hi Mark, With second approach:
e.g. secretPasswordValue=${env.PASSWORD_VARIABLE} is returning the value ${env.PASSWORD_VARIABLE} instead of the value set in environment. Am I missing anything?? Running the code on Wildfly V14 and using javax.inject library, testing on Windows platform, wherein manually setting the environment variables. Thanks & Regards |
Regarding approach 1 - can you provide the stack trace you are seeing? At least the non-sensitive lines involving packages in "io.xlate" and those involving the application server? Regarding approach 2 - the properties file does not need to be in the WAR file. My understanding of the |
Hi Mike, Thanks for the response. Regarding Approach 1 following is the stack trace when i invoke the service for first time:
When I try for second time, it just works... Expected response from Rest service below:
For Approach 2 : I will work and share the outcome soon. Regards |
Hi Mark, Regarding Approach 2, wherein I am using mix of application.properties and environment variable, got the following exception:
My Properties File: Had set the MONGODB_PORT as environment variable on my local machine. Thanks |
Hi Mark, For the second approach wherein I have removed @PropertyResource annotation from all class variables , how does the library resolves the value from environment variable? As the value is being set in properties file 'classVariable=${env.ENV_VALUE}' , what should be the approach to set the values class it's referenced? I believe, I am missing some config here... Thanks |
@milindbangar79 - does this file exist on your application's class path? It seems that neither of the properties files are on the class path based on the stack traces. I published an updated version with some refactoring done to the resource (properties file) lookup code. Please try updating to version 1.0.4 and see if that helps. https://github.com/xlate/property-inject/wiki/Maven-Configuration |
Hi,
I am using the following code within a POJO:
@Inject @Property(resolveEnvironment = true) private String abc;
I have created an environment variable of the same name, but always get an exception while Injecting the property and assigning the value.
Queries:
Kindly help.
Thanks
Milind
The text was updated successfully, but these errors were encountered: