Skip to content

Make request/reply auto-configuration excludable (#8); document context propagation (#50)#56

Merged
helios57 merged 1 commit into
masterfrom
bugfix/issue-8-autoconfiguration-exclusion
Jun 23, 2026
Merged

Make request/reply auto-configuration excludable (#8); document context propagation (#50)#56
helios57 merged 1 commit into
masterfrom
bugfix/issue-8-autoconfiguration-exclusion

Conversation

@helios57

Copy link
Copy Markdown
Collaborator

Addresses both open issues.

#8RequestReplyAutoConfiguration cannot be excluded in tests (fix)

Root cause: the per-binding reply-consumer registration lived in an ApplicationContextInitializer registered through META-INF/spring.factories. Spring Boot applies such initializers to every application context it creates — including sliced tests such as @JsonTest — and they cannot be turned off with @ImportAutoConfiguration(exclude = RequestReplyAutoConfiguration.class) or spring.autoconfigure.exclude. Because the registered reply consumers depend on the RequestReplyServiceImpl bean (absent in a slice), the context failed to start with No bean named 'requestReplyServiceImpl' available.

Fix: the registration is moved into a new RequestReplyFunctionRegistrar (an ImportBeanDefinitionRegistrar that is @Imported by RequestReplyAutoConfiguration), and the ApplicationContextInitializer entry is removed from spring.factories. The registration now runs only when the auto-configuration itself is active, so a slice — or an explicit exclusion — also disables the reply-consumer registration. It still runs during configuration parsing, i.e. early enough for spring-cloud-function/stream to discover the FunctionRegistration beans, and resolves the service bean lazily by type. A guard avoids overriding an application-defined bean that happens to share a binding name.

#50 — context propagation across asynchronous stages (documentation)

The actual fix (wrapping the executor instead of individual tasks so the captured context is restored for every CompletableFuture stage, including stages the application chains onto the returned future) was already merged and released in 6.0.2 — it was simply missing from the docs. This PR adds the missing 6.0.2 CHANGELOG entry and a README section describing the behaviour. No code change for #50.

Tests

Both new tests were verified red before the fix and green after:

  • RequestReplyAutoConfigurationExclusionTests — the reporter's exact @JsonTest slice scenario.
  • RequestReplyExcludeAutoConfigurationTests — explicit spring.autoconfigure.exclude / @ImportAutoConfiguration(exclude = ...).

The existing full-context integration tests (sample @SpringBootApplications consuming the auto-config, bindingMapping and function definitions) continue to pass, confirming normal usage is unaffected. mvn clean package: 87 tests pass, and the packaged jar was verified to contain the corrected spring.factories, the unchanged AutoConfiguration.imports, and the new registrar.

Documentation

Closes #8
Closes #50

…xt propagation (#50)

Issue #8: the per-binding reply-consumer registration lived in an
ApplicationContextInitializer registered via spring.factories. Spring applies
such initializers to every application context it creates - including sliced
tests such as @jsontest - and they cannot be turned off via
@ImportAutoConfiguration(exclude = ...) or spring.autoconfigure.exclude. Because
the registered reply consumers depend on the RequestReplyServiceImpl bean (which
is absent in a slice), the context failed to start.

Move the registration into RequestReplyFunctionRegistrar, an
ImportBeanDefinitionRegistrar imported by RequestReplyAutoConfiguration, and
remove the ApplicationContextInitializer entry from spring.factories. The
registration now runs only when the auto-configuration itself is active, so
excluding the auto-configuration also disables the reply-consumer registration.

Issue #50 (context propagation to every CompletableFuture stage) was already
fixed and released in 6.0.2 but was missing from the documentation. Add the
6.0.2 CHANGELOG entry and a README section describing the behaviour.

Tests (both verified red before the fix, green after):
- RequestReplyAutoConfigurationExclusionTests: the reporter's @jsontest scenario
- RequestReplyExcludeAutoConfigurationTests: explicit spring.autoconfigure.exclude
Full suite: 87 tests pass.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes the request/reply auto-configuration properly excludable (especially for sliced tests) by moving reply-consumer registration out of a globally-applied ApplicationContextInitializer and into an auto-config-scoped registrar, and it adds documentation/changelog entries around context propagation behavior.

Changes:

  • Replaced the ApplicationContextInitializer-based function registration with an ImportBeanDefinitionRegistrar imported by RequestReplyAutoConfiguration, and removed the initializer entry from META-INF/spring.factories.
  • Added regression tests covering @JsonTest slicing and explicit auto-config exclusion.
  • Added README + CHANGELOG documentation for context propagation and the exclusion behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/test/java/community/solace/spring/cloud/requestreply/service/RequestReplyExcludeAutoConfigurationTests.java Adds a full-context test verifying exclusion via spring.autoconfigure.exclude prevents request/reply beans from being contributed.
src/test/java/community/solace/spring/cloud/requestreply/service/RequestReplyAutoConfigurationExclusionTests.java Adds a slice-test regression for issue #8 ensuring @JsonTest starts cleanly without reply-consumer registration.
src/main/resources/META-INF/spring.factories Removes the auto-config-as-initializer registration so it no longer applies to every context.
src/main/java/community/solace/spring/cloud/requestreply/service/RequestReplyFunctionRegistrar.java Introduces registrar that conditionally registers per-binding FunctionRegistration beans only when the auto-config is active.
src/main/java/community/solace/spring/cloud/requestreply/service/RequestReplyAutoConfiguration.java Stops implementing ApplicationContextInitializer and imports the new registrar.
README.md Documents context propagation across async stages and how to exclude the starter in tests.
CHANGELOG.md Adds Unreleased fix note for #8 and the missing 6.0.2 note for #50.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@helios57 helios57 merged commit d0e2519 into master Jun 23, 2026
4 checks passed
@helios57 helios57 deleted the bugfix/issue-8-autoconfiguration-exclusion branch June 25, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants