refactor(#158): collapse NotificationServiceImpl to a single constructor#164
Merged
Merged
Conversation
The #158 migration introduced two constructors (production + test-seam) with the production one @Autowired. That two-constructor shape was the footgun that briefly broke CI ("No default constructor found" when the @Autowired was initially missing). Replace both with a single constructor that injects the autoconfigured RestClient.Builder and builds the client once. Being the sole constructor, Spring selects it for injection without @Autowired, and tests pass their own RestClient.builder(). Net simplification; removes the disambiguation hazard entirely. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
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.
Follow-up cleanup to #158 (PR #163).
The #158 sender migration introduced two constructors on
NotificationServiceImpl— a production one (builtRestClientinternally) and a test-seam one (injected a pre-builtRestClient). That shape was the footgun that briefly turned CI red: with two constructors and neither@Autowired, Spring reported "No default constructor found" and every full-context@SpringBootTestin common failed. The fix at the time was to add@Autowired— but the cleaner answer is to not have two constructors at all.Change
RestClient.Builder, building the client once. As the sole constructor, Spring selects it for injection with no@Autowiredneeded — the disambiguation hazard is gone.RestClient.builder()(still points the JDKHttpServerstub at the service); no test-only production constructor remains.Why
RestClient.Builder(not internalRestClient.create())RestClientAutoConfigurationalways provides a prototypeRestClient.Builderwhen spring-web is on the classpath, so injecting it is safe in every context and keeps the client configurable/test-injectable through one path — which was the only reason the second constructor existed.Verified locally:
DataCustodianApplicationH2Testboots the full context, and the codec + producer wire-contract tests pass.