3

I'm currently experiencing the following exception when my spring application starts:

2012-04-27 17:42:51,021 ERROR [main] com.hazelcast.impl.FactoryImpl - /10.188.31.125:54327 [dev] ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.context.support.ClassPathXmlApplicationContext@1fd0fafc: startup date [Fri Apr 27 17:42:46 CEST 2012]; root of context hierarchy
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.context.support.ClassPathXmlApplicationContext@1fd0fafc: startup date [Fri Apr 27 17:42:46 CEST 2012]; root of context hierarchy
       at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:337) [spring-context-3.1.0.RELEASE.jar:3.1.0.RELEASE]
       at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:324) [spring-context-3.1.0.RELEASE.jar:3.1.0.RELEASE]
       at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:263) ~[spring-data-commons-core-1.2.1.RELEASE.jar:na]
       at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:364) ~[spring-data-commons-core-1.2.1.RELEASE.jar:na]
       at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:570) ~[spring-core-3.1.0.RELEASE.jar:3.1.0.RELEASE]
       at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:247) ~[spring-data-commons-core-1.2.1.RELEASE.jar:na]
       at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:364) ~[spring-data-commons-core-1.2.1.RELEASE.jar:na]
       at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:570) ~[spring-core-3.1.0.RELEASE.jar:3.1.0.RELEASE]
       at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:247) ~[spring-data-commons-core-1.2.1.RELEASE.jar:na]
       at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:165) ~[spring-data-commons-core-1.2.1.RELEASE.jar:na]
       at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:140) ~[spring-data-commons-core-1.2.1.RELEASE.jar:na]
       at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:65) ~[spring-data-commons-core-1.2.1.RELEASE.jar:na]
       at org.springframework.data.mongodb.core.MongoTemplate.determineCollectionName(MongoTemplate.java:1494) ~[spring-data-mongodb-1.0.1.RELEASE.jar:na]
       at org.springframework.data.mongodb.core.MongoTemplate.findAll(MongoTemplate.java:959) ~[spring-data-mongodb-1.0.1.RELEASE.jar:na]
       at net.bigpoint.globalchat.hazelcast.MongoMapStore.loadAllKeys(MongoMapStore.java:59) ~[classes/:na]
       at com.hazelcast.impl.concurrentmap.MapStoreWrapper.loadAllKeys(MapStoreWrapper.java:131) ~[hazelcast-2.0.2.jar:2.0.2]
       at com.hazelcast.impl.FactoryImpl.checkInitialization(FactoryImpl.java:588) [hazelcast-2.0.2.jar:2.0.2]
       at com.hazelcast.impl.FactoryImpl.getOrCreateProxyByName(FactoryImpl.java:546) [hazelcast-2.0.2.jar:2.0.2]
       at com.hazelcast.impl.FactoryImpl.getMap(FactoryImpl.java:514) [hazelcast-2.0.2.jar:2.0.2]
       at com.hazelcast.impl.FactoryImpl$HazelcastInstanceProxy.getMap(FactoryImpl.java:240) [hazelcast-2.0.2.jar:2.0.2]
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_27]
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_27]
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_27]
       at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_27]
       at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:149) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
       at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:570) [spring-beans-3.1.0.RELEASE.jar:3.1.0.RELEASE]
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactory

Background:

  • my authenticationProvider for spring-security requires a hazelcast map
  • hazelcast loads data at startup from a mapstore that is based on spring-data for mongo
  • spring data wants to use the ApplicationEventMulticaster
  • it's not there yet.

as far as i can tell the Multicaster is created when init() on the configurableApplicationContext is called, which seem to happen after the spring security stuff. (imediately after...)

can i force the the application context to set up the multicaster earlier or to set up hazelcast later?

4

1 回答 1

4

不确定它是 Spring Security 还是一般 Spring 问题,但 Spring Security 类在init()调用之前被初始化configurableApplicationContext(所以在ApplicationEventMulticaster创建之前)。

我认为这是一个重要问题,因为解决此问题的唯一方法是从我的安全实现中删除依赖注入,并在第一次使用时从应用程序上下文中手动获取所有内容(我现在已经这样做了)。

我可能会为此提出一个 Jira 问题。

于 2012-05-06T12:48:21.973 回答