Skip to content
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

Inconsistent behavior of Environment binding properties in SCS parent-child contexts #3039

Open
moarychan opened this issue Nov 14, 2024 · 3 comments
Milestone

Comments

@moarychan
Copy link

The Environment instance in the SCS parent and child contexts are ApplicationServletEnvironment and SystemEnvironmentPropertySource respectively, which causes the property values ​​they obtain to be inconsistent with expectations, for example: for a property spring.cloud.azure.eventhubs.connection-string, if configuring SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTIONSTRING, then it cannot be got by env in sub context, see the logic from checkPropertyName
Describe the issue
I can see the parent context using SystemEnvironmentPropertyMapper to map candidate to find the property value; but the sub context does not leverage the mapper,
scs-binding-props

To Reproduce
Steps to reproduce the behavior:

  1. Base on Kafka binder usage, registry a configuration for sub context, such as spring.cloud.stream.binders.kafka.environment.spring.main.sources=com.reproducer.MyConfig
  2. Define a connectionString bean with the condition @ConditionalOnProperty("a.b.connection-string")
  3. Configure an environment variable, A_B__CONNECTIONSTRING=connection-string-value
  4. Run the app, the connectionString bean is not registered into sub context.

Version of the framework Spring Boot 3.3.5 & Spring Cloud Stream 4.1.3
Expected behavior To get same candidates against SystemEnvironmentPropertyMapper mapped.
Screenshots
image

Additional context
N/A

@olegz
Copy link
Contributor

olegz commented Dec 5, 2024

The SystemEnvironmentPropertyMapper is not a s-c-stream class and comes from boot.
That said, indeed there are few few workarounds that we had to do to deal with parent/child context and our current mechanisms may work, but it would be preferable if you had a reproducible sample. You can create a small project and push it to github somewhere.

@olegz
Copy link
Contributor

olegz commented Dec 19, 2024

@moarychan Please provide a reproducer project so we can diagnose otherwise this issue will be closed as non-actionable

@moarychan
Copy link
Author

@olegz , thanks for your update!

I added a sample with introduction, please try this reproducer.

@olegz olegz added this to the 4.2.1 milestone Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants