-
I have encountered a really particular case in which I'm unable to resolve a ConfigurationProperty out of an environment variable. I have the following interface created: @ConfigurationProperties("elastic")
interface ElasticConfiguration {
val cloudId: String
val username: String
val password: String
val indexPrefix: String
} Then I inject this configuration in another class: @Singleton
class ElasticsearchDocumentStorer(
private val elasticConfiguration: ElasticConfiguration
) : CoroutineScope {
private val indexPrefix = elasticConfiguration.indexPrefix
suspend fun storeDocument(index: String, document: JsonObject) {
val indexName = "${indexPrefix}-$index"
...
}
} This works OK, however if I change the val indexName = "${elasticConfiguration.indexPrefix}-$index" micronaut throws the following error at runtime, when accessing that method:
The property should be resolving from an environment variable called ELASTIC_INDEX_PREFIX, which at the moment of executing the method is there (I'm printing all env variables and I can see it right before). If I put the property in the application.yml file (as This is happening in Micronaut 2.1.1, and was happening in Micronaut 1.3.5 as well, so I tried to update to see I could fix it, with not luck. Unfortunately, I have been unable to provide a reproducer for this issue; it is only happening under my current project & setup, which uses Kubernetes. If I can be of any help, I am available for a live screen sharing of this issue or private sharing of the code. |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments 5 replies
-
Can you enable the |
Beta Was this translation helpful? Give feedback.
-
Sure, I'll try to do that today. Thanks for the tip. |
Beta Was this translation helpful? Give feedback.
-
I'm not able to start up the Micronaut HTTP server. It says everytime:
I'm running the fatjar created by shadowJar and I've tried every possible fix related to that error that I've found online. It may be because I'm using Vert.x to provide an HTTP server...? I've disabled to Vert.x HTTP server itself, but I cannot make Micronaut start its own server whatsoever... |
Beta Was this translation helpful? Give feedback.
-
Saying this because AFAIK Vert.x also uses Netty for its HTTP server implementation... |
Beta Was this translation helpful? Give feedback.
-
Sounds like you have a pretty complex setup with lots of issues not related to Micronaut itself but more to your project. I suggest to progress this forward you provide an example that reproduces the issue. |
Beta Was this translation helpful? Give feedback.
-
@MikiLoz92 you are likely missing Micronaut HTTP server dependencies. Compare your build with a fresh one generated from https://launch.micronaut.io and try to see what are you missing |
Beta Was this translation helpful? Give feedback.
-
I have managed to procure a reproducer for this issue. It only seems to happen when I put Vert.x as a dependency and use its timer. https://github.com/MikiLoz92/micronaut-configurationpropertiesbug-reproducer To reproduce, run the main function and wait 5 seconds for the timer to trigger. You should see an error. If you uncomment the same property on the application.yml file, the error is gone. I am printing the ENV variables just before the error, and I see the variable that this property is referring to just there, so that's weird. |
Beta Was this translation helpful? Give feedback.
-
@alvarosanchez I did have the Micronaut HTTP server dependencies on my project, but I guess that's a separate issue... |
Beta Was this translation helpful? Give feedback.
-
You are using |
Beta Was this translation helpful? Give feedback.
-
The same is happening with Micronaut.run(), could you take another look at it @graemerocher ?? Also, could you direct me to the place in the documentation that states that ConfigurationProperties are only usable from environment variables if and only when the Micronaut server is started? |
Beta Was this translation helpful? Give feedback.
-
stacktrace w/
|
Beta Was this translation helpful? Give feedback.
-
Sorry to bump this again, but has something been changed on 2.3.0 regarding the way @ConfigurationProperties resolve from env variables? Because one of our applications that was working fine on 2.2.2 (after implementing the changes we discussed in this thread), is now failing to start on 2.3.0 because is fails to resolve from env vars. Same setup, same everything, just by changing the version to 2.3.0 it fails. |
Beta Was this translation helpful? Give feedback.
stacktrace w/
Micronaut.run()
: