Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-1657

Creating multiple JPA Repositories with BootstrapMode.DEFERRED causes startup failure

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.2.4 (Moore SR4)
    • Fix Version/s: None
    • Labels:
      None

      Description

      Creating more than one JpaRepository using @EnableJpaRepositories(bootstrapMode = BootstrapMode.DEFERRED) causes an error when starting the application. For example, an application with this configuration:

      @SpringBootApplication
      public class DataDeferredApplication {
      
      	public static void main(String[] args) {
      		SpringApplication.run(DataDeferredApplication.class, args);
      	}
      
      	@Configuration
      	@EnableJpaRepositories(bootstrapMode = BootstrapMode.DEFERRED)
      	static class FirstJpaRepositoryConfiguration {}
      
      	@Configuration
      	@EnableJpaRepositories(bootstrapMode = BootstrapMode.DEFERRED)
      	static class SecondJpaRepositoryConfiguration {}
      }
      

      Results in this error at startup:

      java.lang.IllegalStateException: Failed to load ApplicationContext
      
      ...
      
      Caused by: java.lang.IllegalStateException: Could not register object [org.springframework.data.repository.config.DeferredRepositoryInitializationListener@45cff11c] under bean name 'org.springframework.data.repository.config.DeferredRepositoryInitializationListener': there is already object [org.springframework.data.repository.config.DeferredRepositoryInitializationListener@207ea13] bound
      	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.registerSingleton(DefaultSingletonBeanRegistry.java:120)
      	at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerSingleton(DefaultListableBeanFactory.java:1058)
      	at org.springframework.data.repository.config.RepositoryConfigurationDelegate.potentiallyLazifyRepositories(RepositoryConfigurationDelegate.java:231)
      	at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:182)
      	at org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport.registerBeanDefinitions(RepositoryBeanDefinitionRegistrarSupport.java:107)
      	at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.lambda$loadBeanDefinitionsFromRegistrars$1(ConfigurationClassBeanDefinitionReader.java:385)
      	at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
      	at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:384)
      	at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:148)
      	at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:120)
      	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331)
      	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
      	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
      	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
      	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706)
      	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
      	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
      	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
      	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
      	at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:126)
      	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
      	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
      	... 64 more
      

      Reporting this against Data JPA because that appears to be the only type of repository that provides the bootstrapMode configuration with the @Enable...Repositories annotation, but you will get the same error if any two Spring Data repositories are configured with BootstrapMode set to DEFERRED.

        Attachments

          Activity

            People

            Assignee:
            mp911de Mark Paluch
            Reporter:
            scottyfred Scott Frederick
            Last updater:
            Jens Schauder
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: