Skip adding CrudRepository when already on Spring Data 3.x#996
Merged
steve-aom-elliott merged 1 commit intomainfrom Apr 10, 2026
Merged
Skip adding CrudRepository when already on Spring Data 3.x#996steve-aom-elliott merged 1 commit intomainfrom
steve-aom-elliott merged 1 commit intomainfrom
Conversation
In Spring Data 3.0, PagingAndSortingRepository no longer extends CrudRepository by design. The recipe now checks whether the classpath version of PagingAndSortingRepository still inherits CrudRepository (2.x) before adding the explicit extends. This avoids unwanted changes for projects already on Spring Data 3.x where omitting CrudRepository is intentional.
timtebeek
approved these changes
Apr 10, 2026
4 tasks
Contributor
|
Nice! That sounds like a really smart trick! (and also a good compromise to avoid searching for all usages, which could even be outside the current repository when it’s a library) Also thanks a lot for your reactivity! 🙂 |
Member
And thank you, as always, for the detailed feedback! |
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.
Context
PR Add Spring Data 3.0 upgrade recipe #984 added
MigratePagingAndSortingRepositoryto handle the Spring Data 3.0 change wherePagingAndSortingRepositoryno longer extendsCrudRepository. The recipe adds an explicitCrudRepositoryextends to preserve CRUD methods during migration.However, as noted by @DidierLoiseau, the recipe unconditionally adds
CrudRepositoryto any interface extendingPagingAndSortingRepository— even for projects already on Spring Data 3.x where omittingCrudRepositorymay be an intentional design choice.What this changes
The recipe now checks whether the classpath version of
PagingAndSortingRepositorystill inherits fromCrudRepository(i.e., Spring Data 2.x) before making changes. Since this recipe runs before the dependency version upgrade step inUpgradeSpringData_3_0, the type hierarchy on the classpath reflects the pre-migration state:PagingAndSortingRepositoryextendsCrudRepository→ recipe fires, adds explicitCrudRepositoryPagingAndSortingRepositorydoes not extendCrudRepository→ recipe is a no-opThis is a single
TypeUtils.isAssignableTocheck on the resolvedPagingAndSortingRepositorytype itself.