fix(spring-config): init OkapiMicrometerAutoConfiguration considering multiple PTMs - #81
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Spring context startup failures in OkapiMicrometerAutoConfiguration.micrometerOutboxMetrics() when multiple PlatformTransactionManager beans are present by honoring okapi.transaction-manager-qualifier and avoiding ambiguous provider lookups.
Changes:
- Extracted qualifier-based PTM resolution into
OutboxAutoConfiguration.resolvePlatformTransactionManagerByQualifier(...)and reused it from the required-PTM resolver. - Updated
OkapiMicrometerAutoConfiguration.micrometerOutboxMetrics()to (a) resolve the qualifier explicitly when configured, otherwise (b) useObjectProvider.getIfUnique()so ambiguity results in “no PTM” rather than a startup crash. - Added a dedicated regression test suite covering multiple-PTM, qualifier, bad qualifier, and no-PTM scenarios (including verification of which
DataSourceis bound during the snapshot transaction).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| okapi-spring-boot/src/test/kotlin/com/softwaremill/okapi/springboot/OkapiMicrometerAutoConfigurationTest.kt | Adds regression and behavior tests for PTM selection logic and startup stability under multiple PTMs. |
| okapi-spring-boot/src/main/kotlin/com/softwaremill/okapi/springboot/OutboxAutoConfiguration.kt | Extracts and reuses qualifier-based PTM lookup with Okapi-specific error context. |
| okapi-spring-boot/src/main/kotlin/com/softwaremill/okapi/springboot/OkapiMicrometerAutoConfiguration.kt | Updates Micrometer metrics auto-config to honor qualifier and avoid ambiguous PTM resolution crashes. |
Comments suppressed due to low confidence (1)
okapi-spring-boot/src/main/kotlin/com/softwaremill/okapi/springboot/OutboxAutoConfiguration.kt:313
- Similarly, this message suggests that removing okapi.transaction-manager-qualifier will reliably fall back to auto-resolution. For the outbox scheduler path, auto-resolution can still fail when multiple PTMs exist without a unique/@primary candidate. Consider clarifying that the fallback may still require disambiguation.
"okapi.transaction-manager-qualifier='$qualifier' — bean named '$qualifier' exists " +
"but is of type '${e.actualType.name}', not a PlatformTransactionManager. Check " +
"the property value (likely a typo into a DataSource or other bean name) or " +
"remove it to fall back to auto-resolution.",
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Rafał Wokacz <rafal.wokacz@gmail.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.
Fixes #80: OkapiMicrometerAutoConfiguration.micrometerOutboxMetrics() crashed Spring context startup with NoUniqueBeanDefinitionException whenever 2+ PlatformTransactionManager beans were present — even when okapi.transaction-manager-qualifier was set to disambiguate, since it never looked at that property at all. It used a bare ObjectProvider.getIfAvailable(), which throws on ambiguity instead of returning null or honoring a qualifier.
OutboxAutoConfiguration already had correct qualifier-aware resolution logic (resolvePlatformTransactionManager()), just not shared.
What changed
No behavior change for the existing single-PTM or zero-PTM cases; this only changes what happens when 2+ PlatformTransactionManager beans are present.
Test plan