#26549·hazelcast

SpringAware issue

Author: wind57Created Oct 31, 2025Updated Sep 15, 2026
LabelsType: DefectSource: Community

My team has been dealing with spring and hazelcast for the past 2 years or so, and I hope that this "bug" is going to be helpful for someone in the future.

Just use @SpringAware

This is the advice we kept on reading in the hazelcast documentation when we needed to wire things. Which, surprise, is kind of a lie. All @SpringAware does, is when a certain node receives serialized data and then deserializes it, will call the code related to it. Let me explain it differently:

    @Bean
    HazelcastConfigCustomizer hazelcastConfigCustomizerManagedContext(MyManagedContext managedContext) {
        return config -> config.setManagedContext(managedContext);
    }

you can create your own managed context and register it:

class MyManagedContext implements ManagedContext {
      public Object initialize(Object obj) {
           ...... 
      }
}

what happens is, when you receive an Object over the network and hazelcast deserializes it, it will call your initialize method. In the default implementation that hazelcast has: com.hazelcast.spring.context.SpringManagedContext, all they do is :

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.beanFactory = applicationContext.getAutowireCapableBeanFactory();
    }

and then use that to wire things:

...
this.beanFactory.autowireBean(obj);
resultObject = this.beanFactory.initializeBean(obj, name)
...

There are ZERO guarantees that spring context is refreshed and everything can be wired properly.

Considering that when a node joins the cluster, there is no way to tell it : "wait until I say go" before it can take pipelines, create CQC, etc : it might mean that the context is not ready and all the injection will fail. It happened to us. A LOT.

As such, @SpringAware is basically useless.


What we tried is to create our own context, that would wait for the context to be refreshed. But that, again, is pointless.

Imagine the situation where you have two beans:

@SpringAware
class MyClass { 
  
      @Autowired
       private MyDependency dependency

}

and the second one:

@Bean
QueryCache<X, Y> myCQC() {
   ....
}

this is easily a deadlock. CQC initial query has to run on partition threads, but code that triggers the SpringManagedContext::initialize is run on partition threads also. Surprise!


What if you create things lazy? I mean @Lazy @Bean

There is yet another surprise that hazelcast has:

java.lang.IllegalThreadStateException: Thread[#58,hz.condescending_jemison.partition-operation.thread-3,5,main] cannot make remote call ... 

this happens when you are operating on some partition, and try to create calls that try to operate on different one.

Not going to go into the details of our set-up, but using @SpringAware seems very wrong and buggy.