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

Creating multiple JPA Repositories with BootstrapMode.DEFERRED causes startup failure [DATACMNS-1657] #2080

Closed
spring-projects-issues opened this issue Jan 21, 2020 · 2 comments
Assignees
Labels
for: external-project

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Jan 21, 2020

Scott Frederick opened DATACMNS-1657 and commented

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.


Affects: 2.2.4 (Moore SR4)

1 votes, 2 watchers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Dec 11, 2020

gaocong0511 commented

When using BootstrapMode.DEFERRED in more than one @EnableJpaRepositories annotation(scanning different base packages)will cause this problem. However, it didn't occurred when using BootstrapMode.LAZY

@spring-projects-issues spring-projects-issues added type: bug in: repository type: task labels Dec 30, 2020
@mp911de
Copy link
Member

@mp911de mp911de commented Jan 26, 2021

That issue will be handled in Spring Boot via spring-projects/spring-boot#24248.

@mp911de mp911de closed this as completed Jan 26, 2021
@mp911de mp911de added for: external-project and removed in: repository type: bug type: task labels Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project
Projects
None yet
Development

No branches or pull requests

2 participants