-
Notifications
You must be signed in to change notification settings - Fork 41.8k
Allow beans created in MockRestServiceServerAutoConfiguration to be replaced by user-provided alternatives #48825
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
Closed
+61
−0
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wilkinsona
requested changes
Jan 14, 2026
Member
wilkinsona
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much for the PR, @HuitaePark. I've left some comments for your consideration.
...ringframework/boot/restclient/test/autoconfigure/MockRestServiceServerAutoConfiguration.java
Outdated
Show resolved
Hide resolved
...ramework/boot/restclient/test/autoconfigure/MockRestServiceServerAutoConfigurationTests.java
Outdated
Show resolved
Hide resolved
...ramework/boot/restclient/test/autoconfigure/MockRestServiceServerAutoConfigurationTests.java
Outdated
Show resolved
Hide resolved
bbddc8d to
d5bcbda
Compare
Contributor
Author
|
@wilkinsona Thanks for the review. I've applied the changes. |
Previously, MockRestServiceServerAutoConfiguration unconditionally defined a MockServerRestClientCustomizer bean, which prevented user overrides. This commit adds @ConditionalOnMissingBean to ensure the auto-configuration backs off when a user-provided customizer is present. Closes spring-projectsgh-46853 Signed-off-by: HuitaePark <qkrgmlxo3174@gmail.com>
d5bcbda to
4d9a9da
Compare
wilkinsona
approved these changes
Jan 16, 2026
wilkinsona
pushed a commit
that referenced
this pull request
Jan 16, 2026
Previously, MockRestServiceServerAutoConfiguration unconditionally defined its beans, preventing the user from providing an alternative. This commit adds @ConditionalOnMissingBean to ensure the auto-configuration backs off when a user-provided alternatives are present. See gh-48825 Signed-off-by: HuitaePark <qkrgmlxo3174@gmail.com>
wilkinsona
added a commit
that referenced
this pull request
Jan 16, 2026
Member
|
Thanks very much, @HuitaePark. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related Issue
Closes gh-46853
Goal
Allow overriding the MockServerRestClientCustomizer bean created by MockRestServiceServerAutoConfiguration.
This is particularly useful for scenarios in 'RestClientTest' where customization of the mock server behavior is required, such as enabling content buffering via setBufferContent(true), which was previously overridden by the default auto-configuration.
Background
Currently, MockRestServiceServerAutoConfiguration unconditionally defines a MockServerRestClientCustomizer bean:
Because of this unconditional registration, if a user attempts to provide their own MockServerRestClientCustomizer bean to customize the MockRestServiceServer, the auto-configured bean may take precedence or cause conflicts. This prevents users from applying necessary configurations like enabling the buffering of response bodies.
Approach
Apply conditional registration:
Added @ConditionalOnMissingBean to the mockServerRestClientCustomizer bean definition in MockRestServiceServerAutoConfiguration.
This ensures that the auto-configuration backs off if a user has already defined a MockServerRestClientCustomizer bean in the application context.
Verification
I introduced a new test class MockRestServiceServerAutoConfigurationTests using ApplicationContextRunner to verify the fix.
The tests cover two scenarios:
Default Behavior: Verifies that MockServerRestClientCustomizer is registered by the auto-configuration when no user bean is present.
Override Behavior: Verifies that the auto-configuration backs off when a user-provided MockServerRestClientCustomizer is present, ensuring the user's bean is used.