Reputation: 727
I'm new to spring-boot and hazelcast. I have a spring-boot application with a service layer which should use a hazelcast imap. The problem I have is that I don't know how I get the mapstore which stores the data to a spring component with only java configuration. Adding the component annotation is not enough and my autowired repository is null.
@Component
public class MyMapStore extends implements MapStore<Long, MyClass>, MapLoaderLifecycleSupport{
@Autowired
private MyRepository repository;
...
}
I wrote a static ContextAccessor to load my bean, manually but this only works in the IDEs environment and not if I start my application as jar
@Component
public class MyMapStore extends implements MapStore<Long, MyClass>, MapLoaderLifecycleSupport{
private MyRepository repository = StaticContextAccessor.getBean(MyRepository.class);
...
}
The problem here is that not all beans have bean loaded already and the repository is not initialized.
Is there any posibility to get the mapstore running as spring component or even force hazelcast to be initializes after my repositories have been loaded? Thanks for your help.
Upvotes: 2
Views: 1430
Reputation: 1642
You can wire-up and instantiate your MapStore in Spring and then use mapStoreConfig.setImplementation(yourSpringMapStore)
method while preparing the Config (including MapConfig) for Hazelcast.
You can then start Hazelcast manually or in spring using a factory-method.
Upvotes: 3