Uploaded image for project: 'Spring Data for Apache Solr'
  1. Spring Data for Apache Solr
  2. DATASOLR-286

CDI extension conflicts with other Spring Data modules

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.5 GA (Gosling)
    • Fix Version/s: None
    • Component/s: Repository
    • Labels:
    • Environment:
      Jboss AS 7.1, but possibly any CDI environment

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                cstrobl Christoph Strobl
                Reporter:
                bg_eagle Bartek
                Last updater:
                Mark Paluch
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: