Repository navigation
Description
Christopher Smith opened SPR-12902 and commented
I hit a bizarre bug in my application that has several StackOverflow and similar posts around the Web. Each time there's been an immediate workaround, but the behavior smells like a bug in the DI dependency algorithms, and I wanted to raise it for review.
The problem manifests when a component used by MVC, such as a Converter or argument resolver, depends on a Spring Data repository. Attempting to create the component's bean throws an IllegalStateException with the message
ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@491b9b8: startup date [Fri Apr 10 03:28:32 CDT 2015]; root of context hierarchy
Removing the dependency on the repository bean or the implements clause that makes it interesting to MVC makes the exception go away. Injecting via field or constructor makes no difference. Creating the bean via component scanning or an @Bean method (with parameter or configuration-field injection) makes no difference. The issue has been seen with JPA, MongoDB, and Neo4J repositories.
Workarounds have suggested "use the latest snapshot of Spring library $FOO", but I believe this is masking the bug: I have sandbox Spring Boot launchers for my (multi-module) core Maven project and my (multi-module) application project that depends on it; all of the Spring dependencies are of identical versions, and only the application launcher throws the exception while the core launcher starts normally. Both are obtaining the MongoDB configuration from a common CloudConfig class in the core project, using the same properties file for connection parameters.
This appears to be a fairly nondeterministic failure, and the apparent sensitivity on irrelevant details like the existence of extraneous beans makes me suspect that the problem is in the DI container, but it might be a bug in the Spring Data mapping code.
Similar reports:
- Boot + Security + Data Rest + Data MongoDB = ApplicationEventMulticaster not initialized spring-boot#1195
- http://stackoverflow.com/questions/26105148/spring-boot-mvc-converter-cannot-autowire-neo4j-data-repositories
- http://stackoverflow.com/questions/8330414/java-lang-illegalstateexception-applicationeventmulticaster-not-initialized
Stack trace:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'stringKeyToImageAssetConverter' defined in file [/home/christopher/git/studio/studio-domain-core/target/classes/com/artsquare/studio/domain/converter/StringKeyToImageAssetConverter.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.artsquare.studio.domain.repository.ImageAssetRepository]: : Error creating bean with name 'imageAssetRepository': Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoTemplate]: Factory method 'mongoTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingMongoConverter' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.convert.MappingMongoConverter]: Factory method 'mappingMongoConverter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@491b9b8: startup date [Fri Apr 10 03:45:47 CDT 2015]; root of context hierarchy; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'imageAssetRepository': Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoTemplate]: Factory method 'mongoTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingMongoConverter' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.convert.MappingMongoConverter]: Factory method 'mappingMongoConverter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@491b9b8: startup date [Fri Apr 10 03:45:47 CDT 2015]; root of context hierarchy
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.context.support.AbstractApplicationContext.initMessageSource(AbstractApplicationContext.java:625)
at org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:468)
at org.springframework.context.support.AbstractApplicationContext.jrLockAndRefresh(AbstractApplicationContext.java)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:139)
at com.artsquare.gallery.sandbox.SandboxLauncher.main(SandboxLauncher.java:18)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'stringKeyToImageAssetConverter' defined in file [/home/christopher/git/studio/studio-domain-core/target/classes/com/artsquare/studio/domain/converter/StringKeyToImageAssetConverter.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.artsquare.studio.domain.repository.ImageAssetRepository]: : Error creating bean with name 'imageAssetRepository': Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoTemplate]: Factory method 'mongoTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingMongoConverter' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.convert.MappingMongoConverter]: Factory method 'mappingMongoConverter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@491b9b8: startup date [Fri Apr 10 03:45:47 CDT 2015]; root of context hierarchy; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'imageAssetRepository': Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoTemplate]: Factory method 'mongoTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingMongoConverter' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.convert.MappingMongoConverter]: Factory method 'mappingMongoConverter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@491b9b8: startup date [Fri Apr 10 03:45:47 CDT 2015]; root of context hierarchy
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1131)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1034)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:523)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.getDefaultConversionService(ConfigurationPropertiesBindingPostProcessor.java:363)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:282)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:250)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1558)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'imageAssetRepository': Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoTemplate]: Factory method 'mongoTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingMongoConverter' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.convert.MappingMongoConverter]: Factory method 'mappingMongoConverter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@491b9b8: startup date [Fri Apr 10 03:45:47 CDT 2015]; root of context hierarchy
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1469)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1127)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
... 39 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoTemplate]: Factory method 'mongoTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingMongoConverter' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.convert.MappingMongoConverter]: Factory method 'mappingMongoConverter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@491b9b8: startup date [Fri Apr 10 03:45:47 CDT 2015]; root of context hierarchy
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 53 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoTemplate]: Factory method 'mongoTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingMongoConverter' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.convert.MappingMongoConverter]: Factory method 'mappingMongoConverter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@491b9b8: startup date [Fri Apr 10 03:45:47 CDT 2015]; root of context hierarchy
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 62 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingMongoConverter' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.convert.MappingMongoConverter]: Factory method 'mappingMongoConverter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@491b9b8: startup date [Fri Apr 10 03:45:47 CDT 2015]; root of context hierarchy
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:322)
at com.artsquare.studio.config.StudioMongoConfig$$EnhancerBySpringCGLIB$$5affeadb.mappingMongoConverter(<generated>)
at org.springframework.data.mongodb.config.AbstractMongoConfiguration.mongoTemplate(AbstractMongoConfiguration.java:95)
at com.artsquare.studio.config.StudioMongoConfig$$EnhancerBySpringCGLIB$$5affeadb.CGLIB$mongoTemplate$6(<generated>)
at com.artsquare.studio.config.StudioMongoConfig$$EnhancerBySpringCGLIB$$5affeadb$$FastClassBySpringCGLIB$$d28108ee.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
at com.artsquare.studio.config.StudioMongoConfig$$EnhancerBySpringCGLIB$$5affeadb.mongoTemplate(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 63 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.convert.MappingMongoConverter]: Factory method 'mappingMongoConverter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@491b9b8: startup date [Fri Apr 10 03:45:47 CDT 2015]; root of context hierarchy
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 84 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext' defined in class path resource [com/artsquare/studio/config/StudioMongoConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@491b9b8: startup date [Fri Apr 10 03:45:47 CDT 2015]; root of context hierarchy
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:322)
at com.artsquare.studio.config.StudioMongoConfig$$EnhancerBySpringCGLIB$$5affeadb.mongoMappingContext(<generated>)
at org.springframework.data.mongodb.config.AbstractMongoConfiguration.mappingMongoConverter(AbstractMongoConfiguration.java:192)
at com.artsquare.studio.config.StudioMongoConfig$$EnhancerBySpringCGLIB$$5affeadb.CGLIB$mappingMongoConverter$7(<generated>)
at com.artsquare.studio.config.StudioMongoConfig$$EnhancerBySpringCGLIB$$5affeadb$$FastClassBySpringCGLIB$$d28108ee.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
at com.artsquare.studio.config.StudioMongoConfig$$EnhancerBySpringCGLIB$$5affeadb.mappingMongoConverter(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 85 more
Caused by: java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@491b9b8: startup date [Fri Apr 10 03:45:47 CDT 2015]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:344)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:331)
at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:307)
at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:257)
at org.springframework.data.mapping.context.AbstractMappingContext.initialize(AbstractMappingContext.java:373)
at org.springframework.data.mapping.context.AbstractMappingContext.afterPropertiesSet(AbstractMappingContext.java:363)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
... 104 more
Trivial component class triggering the exception:
@Component
public class StringKeyToImageAssetConverter implements Converter<String, ImageAsset> {
final ImageAssetRepository repository;
@Autowired
public StringKeyToImageAssetConverter(ImageAssetRepository repository) {
this.repository = repository;
}
@Override
public ImageAsset convert(String source) {
return repository.findByKey(source);
}
}
List of dependencies for working core launcher:
aopalliance:aopalliance:jar:1.0:compile
ch.qos.logback:logback-classic:jar:1.1.2:compile
ch.qos.logback:logback-core:jar:1.1.2:compile
com.artsquare.gallery.api:artsquare-gallery-api:jar:0.3.2-SNAPSHOT:compile
com.artsquare.studio:studio-deployment:jar:2015.4.8-106:compile
com.artsquare.studio:studio-domain-core:jar:2015.4.8-106:compile
com.artsquare.studio:studio-domain-events:jar:2015.4.8-106:compile
com.artsquare.studio:studio-image-processing-api:jar:2015.4.8-106:compile
com.artsquare.studio:studio-image-processing-blitline:jar:2015.4.8-106:compile
com.artsquare.studio:studio-image-processing-generic:jar:2015.4.8-106:compile
com.artsquare.studio:studio-image-s3:jar:2015.4.8-106:compile
com.artsquare.studio:studio-security-inmemory:jar:2015.4.8-106:compile
com.artsquare.studio:studio-security-stormpath:jar:2015.4.8-106:compile
com.artsquare.studio:studio-security:jar:2015.4.8-106:compile
com.artsquare.studio:studio-wiring:jar:2015.4.8-106:compile
com.blitline:blitline-image-client-spring:jar:0.15.0:compile
com.blitline:blitline-image-client:jar:0.15.0:compile
com.chrylis:base58-codec:jar:1.2.0:compile
com.fasterxml.jackson.core:jackson-annotations:jar:2.4.4:compile
com.fasterxml.jackson.core:jackson-core:jar:2.4.4:compile
com.fasterxml.jackson.core:jackson-databind:jar:2.4.4:compile
com.fasterxml.jackson.dataformat:jackson-dataformat-csv:jar:2.5.1:compile
com.fasterxml:classmate:jar:1.0.0:compile
com.goldmansachs:gs-collections-api:jar:5.1.0:compile
com.goldmansachs:gs-collections:jar:5.1.0:compile
com.google.guava:guava:jar:18.0:compile
com.lmax:disruptor:jar:3.2.1:compile
com.rabbitmq:amqp-client:jar:3.4.3:compile
com.stormpath.sdk:stormpath-sdk-api:jar:1.0.RC3.1:compile
com.stormpath.sdk:stormpath-sdk-httpclient:jar:1.0.RC3.1:compile
com.stormpath.sdk:stormpath-sdk-impl:jar:1.0.RC3.1:compile
commons-codec:commons-codec:jar:1.10:compile
commons-io:commons-io:jar:2.4:compile
io.gatling:jsr166e:jar:1.0:compile
javax.validation:validation-api:jar:1.1.0.Final:compile
log4j:log4j:jar:1.2.17:compile
org.apache.commons:commons-lang3:jar:3.3.2:compile
org.apache.httpcomponents:httpclient:jar:4.3.6:compile
org.apache.httpcomponents:httpcore:jar:4.3.3:compile
org.apache.tomcat.embed:tomcat-embed-core:jar:7.0.57:compile
org.apache.tomcat.embed:tomcat-embed-el:jar:7.0.57:compile
org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:7.0.57:compile
org.apache.tomcat.embed:tomcat-embed-websocket:jar:7.0.57:compile
org.aspectj:aspectjrt:jar:1.8.4:compile
org.aspectj:aspectjweaver:jar:1.8.4:compile
org.codehaus.groovy:groovy-all:jar:indy:2.4.3:compile
org.hamcrest:hamcrest-core:jar:1.3:compile
org.hamcrest:hamcrest-library:jar:1.3:compile
org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
org.hibernate:hibernate-validator:jar:5.1.3.Final:compile
org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
org.mongodb:mongo-java-driver:jar:2.13.0:compile
org.objenesis:objenesis:jar:2.1:compile
org.projectreactor:reactor-core:jar:1.1.5.RELEASE:compile
org.slf4j:jcl-over-slf4j:jar:1.7.8:compile
org.slf4j:jul-to-slf4j:jar:1.7.8:compile
org.slf4j:log4j-over-slf4j:jar:1.7.8:compile
org.slf4j:slf4j-api:jar:1.7.10:compile
org.springframework.amqp:spring-amqp:jar:1.4.2.RELEASE:compile
org.springframework.amqp:spring-rabbit:jar:1.4.2.RELEASE:compile
org.springframework.boot:spring-boot-autoconfigure:jar:1.2.1.RELEASE:compile
org.springframework.boot:spring-boot-starter-aop:jar:1.2.1.RELEASE:compile
org.springframework.boot:spring-boot-starter-integration:jar:1.2.1.RELEASE:compile
org.springframework.boot:spring-boot-starter-logging:jar:1.2.1.RELEASE:compile
org.springframework.boot:spring-boot-starter-tomcat:jar:1.2.1.RELEASE:compile
org.springframework.boot:spring-boot-starter-web:jar:1.2.1.RELEASE:compile
org.springframework.boot:spring-boot-starter:jar:1.2.1.RELEASE:compile
org.springframework.boot:spring-boot:jar:1.2.1.RELEASE:compile
org.springframework.cloud:spring-cloud-cloudfoundry-connector:jar:1.1.0.RELEASE:compile
org.springframework.cloud:spring-cloud-core:jar:1.1.0.RELEASE:compile
org.springframework.cloud:spring-cloud-localconfig-connector:jar:1.1.0.RELEASE:compile
org.springframework.cloud:spring-cloud-spring-service-connector:jar:1.1.0.RELEASE:compile
org.springframework.data:spring-data-commons:jar:1.9.1.RELEASE:compile
org.springframework.data:spring-data-mongodb:jar:1.6.1.RELEASE:compile
org.springframework.data:spring-data-redis:jar:1.4.1.RELEASE:compile
org.springframework.hateoas:spring-hateoas:jar:0.16.0.RELEASE:compile
org.springframework.integration:spring-integration-core:jar:4.1.2.RELEASE:compile
org.springframework.integration:spring-integration-file:jar:4.1.2.RELEASE:compile
org.springframework.integration:spring-integration-http:jar:4.1.2.RELEASE:compile
org.springframework.integration:spring-integration-ip:jar:4.1.2.RELEASE:compile
org.springframework.integration:spring-integration-stream:jar:4.1.2.RELEASE:compile
org.springframework.plugin:spring-plugin-core:jar:1.1.0.RELEASE:compile
org.springframework.retry:spring-retry:jar:1.1.2.RELEASE:compile
org.springframework.security:spring-security-config:jar:4.0.0.RC2:compile
org.springframework.security:spring-security-core:jar:4.0.0.RC2:compile
org.springframework.security:spring-security-web:jar:4.0.0.RC2:compile
org.springframework:spring-aop:jar:4.1.4.RELEASE:compile
org.springframework:spring-beans:jar:4.1.4.RELEASE:compile
org.springframework:spring-context-support:jar:4.1.4.RELEASE:compile
org.springframework:spring-context:jar:4.1.4.RELEASE:compile
org.springframework:spring-core:jar:4.1.4.RELEASE:compile
org.springframework:spring-expression:jar:4.1.4.RELEASE:compile
org.springframework:spring-messaging:jar:4.1.4.RELEASE:compile
org.springframework:spring-tx:jar:4.1.4.RELEASE:compile
org.springframework:spring-web:jar:4.1.4.RELEASE:compile
org.springframework:spring-webmvc:jar:4.1.4.RELEASE:compile
org.yaml:snakeyaml:jar:1.14:compile
Dependencies for broken application launcher:
aopalliance:aopalliance:jar:1.0:compile
ch.qos.logback:logback-classic:jar:1.1.2:compile
ch.qos.logback:logback-core:jar:1.1.2:compile
com.artsquare.gallery.api:artsquare-gallery-api:jar:0.3.2-SNAPSHOT:compile
com.artsquare.gallery:gallery-base-controllers:jar:2015.4.9-234:compile
com.artsquare.gallery:gallery-configuration:jar:2015.4.9-234:compile
com.artsquare.gallery:gallery-html-controllers:jar:2015.4.9-234:compile
com.artsquare.gallery:gallery-html-external:jar:2015.4.9-234:compile
com.artsquare.gallery:gallery-html-resources:jar:2015.4.9-234:compile
com.artsquare.gallery:gallery-json-v0:jar:2015.4.9-234:compile
com.artsquare.gallery:gallery-scaffold:jar:2015.4.9-234:compile
com.artsquare.studio:studio-deployment:jar:2015.4.8-106:compile
com.artsquare.studio:studio-domain-core:jar:2015.4.8-106:compile
com.artsquare.studio:studio-domain-digitization:jar:2015.4.8-106:compile
com.artsquare.studio:studio-domain-events:jar:2015.4.8-106:compile
com.artsquare.studio:studio-image-processing-api:jar:2015.4.8-106:compile
com.artsquare.studio:studio-image-processing-blitline:jar:2015.4.8-106:compile
com.artsquare.studio:studio-image-processing-generic:jar:2015.4.8-106:compile
com.artsquare.studio:studio-image-s3:jar:2015.4.8-106:compile
com.artsquare.studio:studio-policy:jar:2015.4.8-106:compile
com.artsquare.studio:studio-security-inmemory:jar:2015.4.8-106:compile
com.artsquare.studio:studio-security-stormpath:jar:2015.4.8-106:compile
com.artsquare.studio:studio-security:jar:2015.4.8-106:compile
com.artsquare.studio:studio-stripe:jar:2015.4.8-106:compile
com.artsquare.studio:studio-wiring:jar:2015.4.8-106:compile
com.blitline:blitline-image-client-spring:jar:0.15.0:compile
com.blitline:blitline-image-client:jar:0.15.0:compile
com.chrylis:base58-codec:jar:1.2.0:compile
com.fasterxml.jackson.core:jackson-annotations:jar:2.4.4:compile
com.fasterxml.jackson.core:jackson-core:jar:2.4.4:compile
com.fasterxml.jackson.core:jackson-databind:jar:2.4.4:compile
com.fasterxml.jackson.dataformat:jackson-dataformat-csv:jar:2.5.1:compile
com.fasterxml:classmate:jar:1.0.0:compile
com.goldmansachs:gs-collections-api:jar:5.1.0:compile
com.goldmansachs:gs-collections:jar:5.1.0:compile
com.google.code.gson:gson:jar:2.3:compile
com.google.guava:guava:jar:18.0:compile
com.lmax:disruptor:jar:3.2.1:compile
com.rabbitmq:amqp-client:jar:3.4.3:compile
com.stormpath.sdk:stormpath-sdk-api:jar:1.0.RC3.1:compile
com.stormpath.sdk:stormpath-sdk-httpclient:jar:1.0.RC3.1:compile
com.stormpath.sdk:stormpath-sdk-impl:jar:1.0.RC3.1:compile
com.stripe:stripe-java:jar:1.27.0:compile
commons-codec:commons-codec:jar:1.10:compile
commons-logging:commons-logging:jar:1.2:compile
io.gatling:jsr166e:jar:1.0:compile
io.undertow:undertow-core:jar:1.1.1.Final:compile
io.undertow:undertow-servlet:jar:1.1.1.Final:compile
io.undertow:undertow-websockets-jsr:jar:1.1.1.Final:compile
javax.inject:javax.inject:jar:1:compile
javax.servlet:javax.servlet-api:jar:3.1.0:compile
javax.validation:validation-api:jar:1.1.0.Final:compile
log4j:log4j:jar:1.2.17:compile
net.spy:spymemcached:jar:2.11.2:compile
nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:1.2.7:compile
ognl:ognl:jar:3.0.8:compile
opensymphony:ognl:jar:2.6.11:compile
org.apache.commons:commons-lang3:jar:3.3.2:compile
org.apache.commons:commons-pool2:jar:2.2:compile
org.apache.httpcomponents:httpclient:jar:4.3.6:compile
org.apache.httpcomponents:httpcore:jar:4.3.3:compile
org.codehaus.groovy:groovy-all:jar:indy:2.4.3:compile
org.glassfish:javax.el:jar:3.0.0:compile
org.hamcrest:hamcrest-core:jar:1.3:compile
org.hamcrest:hamcrest-library:jar:1.3:compile
org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
org.hibernate:hibernate-validator:jar:5.1.3.Final:compile
org.javassist:javassist:jar:3.18.1-GA:compile
org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
org.jboss.spec.javax.annotation:jboss-annotations-api_1.2_spec:jar:1.0.0.Final:compile
org.jboss.spec.javax.websocket:jboss-websocket-api_1.1_spec:jar:1.1.0.Final:compile
org.jboss.xnio:xnio-api:jar:3.3.0.Final:compile
org.mongodb:mongo-java-driver:jar:2.12.4:compile
org.objenesis:objenesis:jar:2.1:compile
org.projectreactor:reactor-core:jar:1.1.5.RELEASE:compile
org.slf4j:jcl-over-slf4j:jar:1.7.8:compile
org.slf4j:jul-to-slf4j:jar:1.7.8:compile
org.slf4j:log4j-over-slf4j:jar:1.7.8:compile
org.slf4j:slf4j-api:jar:1.7.10:compile
org.springframework.amqp:spring-amqp:jar:1.4.2.RELEASE:compile
org.springframework.amqp:spring-rabbit:jar:1.4.2.RELEASE:compile
org.springframework.boot:spring-boot-autoconfigure:jar:1.2.1.RELEASE:compile
org.springframework.boot:spring-boot-starter-logging:jar:1.2.1.RELEASE:compile
org.springframework.boot:spring-boot-starter-thymeleaf:jar:1.2.1.RELEASE:compile
org.springframework.boot:spring-boot-starter-undertow:jar:1.2.1.RELEASE:compile
org.springframework.boot:spring-boot-starter-web:jar:1.2.1.RELEASE:compile
org.springframework.boot:spring-boot-starter:jar:1.2.1.RELEASE:compile
org.springframework.boot:spring-boot:jar:1.2.1.RELEASE:compile
org.springframework.cloud:spring-cloud-cloudfoundry-connector:jar:1.1.0.RELEASE:compile
org.springframework.cloud:spring-cloud-core:jar:1.1.0.RELEASE:compile
org.springframework.cloud:spring-cloud-localconfig-connector:jar:1.1.0.RELEASE:compile
org.springframework.cloud:spring-cloud-spring-service-connector:jar:1.1.0.RELEASE:compile
org.springframework.data:spring-data-commons:jar:1.9.1.RELEASE:compile
org.springframework.data:spring-data-mongodb:jar:1.6.1.RELEASE:compile
org.springframework.data:spring-data-redis:jar:1.4.1.RELEASE:compile
org.springframework.hateoas:spring-hateoas:jar:0.16.0.RELEASE:compile
org.springframework.integration:spring-integration-core:jar:4.1.2.RELEASE:compile
org.springframework.plugin:spring-plugin-core:jar:1.1.0.RELEASE:compile
org.springframework.retry:spring-retry:jar:1.1.2.RELEASE:compile
org.springframework.security:spring-security-config:jar:4.0.0.RC2:compile
org.springframework.security:spring-security-core:jar:4.0.0.RC2:compile
org.springframework.security:spring-security-web:jar:4.0.0.RC2:compile
org.springframework.session:spring-session-data-redis:jar:1.0.0.RELEASE:compile
org.springframework.session:spring-session:jar:1.0.0.RELEASE:compile
org.springframework.webflow:spring-binding:jar:2.4.1.RELEASE:compile
org.springframework.webflow:spring-js-resources:jar:2.4.1.RELEASE:compile
org.springframework.webflow:spring-js:jar:2.4.1.RELEASE:compile
org.springframework.webflow:spring-webflow:jar:2.4.1.RELEASE:compile
org.springframework:spring-aop:jar:4.1.4.RELEASE:compile
org.springframework:spring-beans:jar:4.1.4.RELEASE:compile
org.springframework:spring-context-support:jar:4.1.4.RELEASE:compile
org.springframework:spring-context:jar:4.1.4.RELEASE:compile
org.springframework:spring-core:jar:4.1.4.RELEASE:compile
org.springframework:spring-expression:jar:4.1.4.RELEASE:compile
org.springframework:spring-messaging:jar:4.1.4.RELEASE:compile
org.springframework:spring-tx:jar:4.1.4.RELEASE:compile
org.springframework:spring-web:jar:4.1.4.RELEASE:compile
org.springframework:spring-webmvc:jar:4.1.4.RELEASE:compile
org.thymeleaf.extras:thymeleaf-extras-springsecurity4:jar:2.1.2-SNAPSHOT:compile
org.thymeleaf:thymeleaf-spring4:jar:2.1.4.RELEASE:compile
org.thymeleaf:thymeleaf:jar:2.1.4.RELEASE:compile
org.unbescape:unbescape:jar:1.1.0.RELEASE:compile
org.yaml:snakeyaml:jar:1.14:compile
redis.clients:jedis:jar:2.5.2:compile
Note: I have found that annotating the injection point with @Lazy seems to work as a workaround, but since nothing explicitly depends on this bean (and if it did, the exception should be one for a circular dependency), eager initialization should work.
Affects: 4.1.4
Issue Links:
- Early ApplicationContext close call may lead to ApplicationEventMulticaster/LifecycleProcessor access exception [SPR-16149] #20697 Early ApplicationContext close call may lead to ApplicationEventMulticaster/LifecycleProcessor access exception
- Annotation-based event listener does not receive event published in @PostConstruct [SPR-15122] #19689 Annotation-based event listener does not receive event published in
@PostConstruct
Referenced from: commits 9ed0a56
Activity
spring-projects-issues commentedon Apr 16, 2015
Juergen Hoeller commented
This is not a new problem; it keeps coming up in some form every now and then. From that perspective, we should try to avoid such a hard
IllegalStateExceptionand provide reasonable fallback behavior instead.That said, the new factor here is Spring Boot: Its
ConfigurationPropertiesBindingPostProcessorrather aggressively builds itsConversionServiceand therefore triggers the creation of Spring Data's converters, which implicitly leads to the publication of some events there.So from my perspective, the problem is threefold:
Spring Boot shouldn't unconditionally trigger such early creation of Spring Data converters from within a
BeanPostProcessorwhich is even applied to very core beans such asMessageSourcethat will be created before theApplicationEventMulticaster. That's "unfriendly behavior" for a bean post-processor.Spring Data shouldn't try to publish events from within its
AbstractMappingContext, given that it may be called at such an early point. Or well, if it insists on doing that, it should guard itspublishEventcall with anIllegalStateExceptioncatch clause, provided that it's ok for such an event to be ignored.Spring's
AbstractApplicationContextcurrently initializes itsMessageSourcebean before theApplicationEventMulticasterbean. The problem would largely go away if we inverted that order. However, a custom multicaster bean may also delegate to some other beans etc, so it wouldn't be completely safe.A straightforward remedy would be to locally accumulate such early events, propagating them to the multicaster once initialized. I suppose the best place to do that would be
AbstractApplicationContextitself. However, we would only do that as of 4.2, so it still makes sense for Boot/Data to be more defensive there.Juergen
spring-projects-issues commentedon Apr 16, 2015
Juergen Hoeller commented
I've implemented the approach I outlined, collecting those early events and publishing them in a batch once the multicaster is available. This definitely needs to go through the 4.2 release candidate phase though.
For 4.1.x, the easiest solution seems to be for Data/Boot to be more defensive there. I would recommend that in general, even against 4.2.
Juergen
spring-projects-issues commentedon Nov 2, 2017
Terence Mill commented
Similar things happen again on spring-cloud dalston ( spring framework 4.3.9.RELEASE)
spring-projects-issues commentedon Nov 2, 2017
Juergen Hoeller commented
Terence Mill, indeed, this seems to be a related issue in
ApplicationListenerDetectorwhich needs to defensively handle a call to theApplicationEventMulticasterfor scenarios where the latter hasn't been initialized yet. Could you please create a separate JIRA ticket for this? I'll sort it out for 4.3.13 then.spring-projects-issues commentedon Nov 2, 2017
Terence Mill commented
Here you are
#20697
Thanks for your support.