web-dev-qa-db-ja.com

Spring Data JPAで複数のデータベースを使用すると、「ConfigurationClassPostProcessor.importRegistry」という名前のBean例外が発生しない

私の春のboot(data)プロジェクトでは、複数のデータベースをセットアップして使用しようとしています。 1つのデータベースはMySqlで、他のデータベースはH2です。カスタムJPA構成を ここに表示 として定義しました。アプリケーションの起動中に例外が発生します

「org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry」という名前のBeanが使用できないという例外は発生しません

Baeldung blog の指示に従いました。

例外ログ

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'applicationAvailability' defined in class path resource [org/springframework/boot/autoconfigure/availability/ApplicationAvailabilityAutoConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' availableorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'applicationAvailability' defined in class path resource [org/springframework/boot/autoconfigure/availability/ApplicationAvailabilityAutoConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:512) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.Java:323) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:226) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:321) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:207) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.Java:245) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.Java:197) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.Java:134) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.Java:403) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.Java:360) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.boot.availability.AvailabilityChangeEvent.publish(AvailabilityChangeEvent.Java:81) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE] 
at org.springframework.boot.availability.AvailabilityChangeEvent.publish(AvailabilityChangeEvent.Java:67) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE] 
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.doClose(ServletWebServerApplicationContext.Java:167) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE] 
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.Java:978) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.Java:814) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE] 
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:325) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE] a
t org.springframework.boot.SpringApplication.run(SpringApplication.Java:1237) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE] 
at org.springframework.boot.SpringApplication.run(SpringApplication.Java:1226) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE] 
at com.pj.multipledatabasesdemo.MultipleDatabasesDemoApplication.main(MultipleDatabasesDemoApplication.Java:12) ~[classes/:na] 
at Java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] 
at Java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62) ~[na:na] 
at Java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43) ~[na:na] 
at Java.base/Java.lang.reflect.Method.invoke(Method.Java:566) ~[na:na] 
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.Java:49) ~[spring-boot-devtools-2.3.0.RELEASE.jar:2.3.0.RELEASE]

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:603) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:517) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.Java:323) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:226) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:321) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:202) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.Java:409) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.Java:1338) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.Java:1177) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:557) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:517) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.Java:323) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:226) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:321) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:207) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.Java:91) ~[spring-aop-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.Java:109) ~[spring-aop-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at 
org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.findCandidateAdvisors(AnnotationAwareAspectJAutoProxyCreator.Java:92) ~[spring-aop-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.Java:101) ~[spring-aop-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.Java:251) ~[spring-aop-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.Java:1141) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.Java:1114) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:506) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] ... 23 common frames omitted

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.Java:814) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.Java:1282) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:297) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:207) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor.postProcessBeforeInitialization(ConfigurationClassPostProcessor.Java:456) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.Java:416) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1788) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:595) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
2
Jadda

はい。この問題は、キャッシュに使用する Redisson 依存関係が原因で発生します。 SQLサーバーであるプライマリデータベースは、休止状態の2次キャッシュと2次データベース(Oracle)が使用しないRedisを使用するように構成されています。しかし、何らかの理由で、2番目のデータベースもRedisson構成を想定し、NullPointerExceptionをスローします。 2番目のデータベースのキャッシュを無効にすると問題が解決しました

注:追加したデモには、SQL ServerおよびOracleデータベースの代わりにMySqlおよびH2データベースが含まれています

1
Jadda