Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Fix Spring Data custom repository fragment lookup. #661

Merged
merged 1 commit into from Apr 1, 2021

Conversation

christophstrobl
Copy link
Contributor

This commit introduces a Substitution for the Spring Data CustomRepositoryImplementationDetector to directly use the CandidateComponentsIndex for repository fragment lookups and adds the missing type hint for the RepositoryFragment required to create the target repository.

This enables fragments following the pattern FragmentInterfaceName | FragmentInterfaceNameImpl to be discovered and registered correctly when annotated with @Component as outlined below.

interface CustomRepository {
	// ... 
}

@Component
class CustomRepositoryImpl implements CustomRepository {
	// ... 
}

interface DomainTypeRepository extends CrudRepository<DomainType, String>, CustomRepository {
	// ... 
}

It also updates the data-elasticsearch example to cover the custom repository setup and retains functionality of the heritage configuration format (used in the data-mongodb).

On the long run it would be beneficial to revisit the ClassPathScanningCandidateComponentProvider for bean lookups using the spring.components index so it supports the in this PR substituted lookup.


Closes: #639

Repository fragments following the pattern FragmentInterface | FragmentInterfaceImpl did not get discovered and registered correctly though annotated with @component.
This commit introduces a Substitution for the CustomRepositoryImplementationDetector using the CandidateComponentsIndex directly. It also adds the missing type hint for the RepositoryFragment used to create the target repository and updates the data-elasticsearch example to cover the custom repository setup.
The alternative setup using the heritage configuration format (used in the data-mongodb) still works.
private Set<BeanDefinition> findCandidateBeanDefinitions(ImplementationDetectionConfiguration config) {

/* Using the index instead of ClassPathScanningCandidateComponentProvider with pattern.
* Not sure why components are not found via the index as it should be configured on
Copy link
Contributor

Choose a reason for hiding this comment

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

@aclement Could you please give us your advice on that question raised by @christophstrobl ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that is worth an issue in its own right. I saw a similar thing whilst working with Josh Long - he was trying to use ClassPathScanningCandidateComponentProvider (IIRC) and it wasn't always able to use the components index - as if the combination of filters you set on it can cause it to not allow index usage.

Copy link
Contributor

Choose a reason for hiding this comment

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

@christophstrobl Could you please create the issue suggested by Andy?

@aclement Do you think we should merge this PR as it is of should we wait the issue mention above to be fixed?

Copy link
Contributor

Choose a reason for hiding this comment

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

@sdeleuze I would say this improves things, let's integrate it. We have the issue for improving things further.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A general bug
Development

Successfully merging this pull request may close these issues.

Custom Spring Data Elasticsearch repository fragment implementation not found when running in native
3 participants