Skip to content
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

CDI extension conflicts with other Spring Data modules [DATASOLR-286] #406

Open
spring-projects-issues opened this issue Mar 22, 2016 · 1 comment

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Mar 22, 2016

Bartek opened DATASOLR-286 and commented

CDI extension does not allow for existence of two different Spring data modules - checked for Spring Data Jpa and Solr, but it looks like the problem is general.

CDI extension looks for every interface extending Repository interface and registers a new repository bean for each found interface without checking the specific repository type related to a concrete Spring Data Module. Each Spring Data module registers a separate CDI extension and do the same processing, trying to register beans specific to that module but including interfaces that are designed for other modules, eg JpaRepositoryExtension processes an interface extending SolrRepository and SolrRepositoryExtension processes an interface extending JpaRepository.

We couldn't find any way to configure this process in CDI environment. We use a simple work around which works for Us but needs replacing files in jars (e.g. javax.enterprise.inject.spi.Extension and extension classes) and publishing fix artifacts when We need upgrade version of a Spring data module.

In the code We create a copy of extension class e.g. JpaRepositoryExtensionFix as a copy of JpaRepositoryExtension and make a small change in the method:
void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBeanDiscovery, BeanManager beanManager)
we add additional check in the main loop:
if (JpaRepository.class.isAssignableFrom(repositoryType))

final code is:

void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBeanDiscovery, BeanManager beanManager) {

		for (Map.Entry<Class<?>, Set<Annotation>> entry : getRepositoryTypes()) {

			Class<?> repositoryType = entry.getKey();
			if (JpaRepository.class.isAssignableFrom(repositoryType)) {
				Set<Annotation> qualifiers = entry.getValue();

				// Create the bean representing the repository.
				CdiRepositoryBean<?> repositoryBean = createRepositoryBean(repositoryType, qualifiers, beanManager);
				LOGGER.info("Registering bean for '{}' with qualifiers {}.", repositoryType.getName(), qualifiers);

				// Register the bean to the extension and the container.
				registerBean(repositoryBean);
				afterBeanDiscovery.addBean(repositoryBean);
			}
		}
	}

More generic solution could incldue changes in spring-data-commons – org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport class, methods: isRepository, processAnnotatedType.

I have made a similar bug in Jpa module: DATAJPA-875


Affects: 1.5 GA (Gosling)

Issue Links:

  • DATAJPA-875 CDI extension conflicts with other Spring Data modules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants