Reputation: 261
I have just started with hazelcast and am trying to do a POC with spring boot 1.5.8.
What i am trying to do to start with is to create a spring boot application in which i have created a Config bean and since i have hazelcast jar on the classpath, spring does create a hazelcast instance for me, which i have used and created an IMap and put in some test values in the map
Any pointers, on how to run hazelcast members and client in the same application?
.Thanks
,
Upvotes: 0
Views: 1620
Reputation: 3150
Try
@Bean
public ClientConfig clientConfig() throws Exception {
return new XmlClientConfigBuilder("hazelcast-client.xml").build();
}
@Bean
public Config config() {
return new ClasspathXmlConfig("hazelcast.xml");
}
@Bean(name="server")
public HazelcastInstance server(Config config) {
return Hazelcast.newHazelcastInstance(config);
}
@Bean(name="client")
@DependsOn("server")
public HazelcastInstance client(ClientConfig clientConfig) {
return HazelcastClient.newHazelcastClient(clientConfig);
}
and access with
@Autowired
@Qualifier("server")
private HazelcastInstance server;
@Autowired
@Qualifier("client")
private HazelcastInstance client;
You need @Depends
on so the server is up before the client.
Upvotes: 1