micronaut-spring icon indicating copy to clipboard operation
micronaut-spring copied to clipboard

MicronautApplicationContext not inheriting parent propertySources

Open zyro23 opened this issue 5 years ago • 2 comments

trying to use testcontainers boot autoconfig which relies on spring-cloud's bootstrap context. that gets registered as a parent context upstream of the micronaut context. but i am not able to resolve its properties from the application.

is the MicronautApplicationContext not supposed to merge the parent environment (i.e. inherit parent propertySources)?

  • https://github.com/micronaut-projects/micronaut-spring/blob/v1.0.2/spring-context/src/main/java/io/micronaut/spring/context/MicronautApplicationContext.java#L312 vs.
  • https://github.com/spring-projects/spring-framework/blob/v5.2.5.RELEASE/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java#L476-L482 maybe?

ref.

  • https://cloud.spring.io/spring-cloud-static/spring-cloud-commons/2.2.1.RELEASE/reference/html/#application-context-hierarchies
  • https://github.com/spring-cloud/spring-cloud-commons/blob/v2.2.1.RELEASE/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/BootstrapApplicationListener.java#L395-L396
  • https://github.com/spring-projects/spring-boot/blob/v2.2.6.RELEASE/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/ParentContextApplicationContextInitializer.java#L58

zyro23 avatar Mar 31 '20 06:03 zyro23

Potentially, if you wish to send a PR for this, contributions welcome!

graemerocher avatar Mar 31 '20 06:03 graemerocher

i started to give it a shot - see the referenced commit. but at that point, i hit java.lang.UnsupportedOperationException: Method parent not supported:

  • https://github.com/micronaut-projects/micronaut-spring/blob/master/spring-context/src/main/java/io/micronaut/spring/context/env/MicronautEnvironment.java#L195

looks like there, a reverse propertySources merging impl. spring env. -> micronaut env. is needed which is not trivial - at least for me.

also, my original use-case was within a grails app. which means the app main context is supposed to inherit the micronaut context propertySources. it does not look like that is currently supported as well:

  • https://github.com/micronaut-projects/micronaut-spring/blob/master/spring-context/src/main/java/io/micronaut/spring/context/env/MicronautEnvironment.java#L164

maybe GrailsApp can check if the parent micronaut context has another parent and if so, try merging its environment directly. but that would be a grails issue.

if this is going to stall without further contributions from my side, feel free to close as not-supported.
thanks for your feedback!

zyro23 avatar Mar 31 '20 08:03 zyro23