Skip to content

Instantly share code, notes, and snippets.

@sandheepgr
Created September 7, 2016 04:43
Show Gist options
  • Save sandheepgr/c715ce530a279b27a8144ef834c19918 to your computer and use it in GitHub Desktop.
Save sandheepgr/c715ce530a279b27a8144ef834c19918 to your computer and use it in GitHub Desktop.
Hazelcast configuration
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.spring.cache.HazelcastCacheManager;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import java.util.concurrent.TimeUnit;
/**
* Created by sandheepgr on 21/2/15.
*/
@Configuration
@EnableCaching
@PropertySource("classpath:cache.properties")
public class CacheConfig {
@Value("${cache.hostname}")
private String cacheHostName = "";
@Value("${cache.port}")
private int cachePort ;
@Value("${cache.username}")
private String cacheUsername ;
@Value("${cache.password}")
private String cachePassword ;
@Bean
public CacheManager cacheManager() {
ClientConfig config = new ClientConfig();
config.getGroupConfig().setName(cacheUsername);
config.getGroupConfig().setPassword(cachePassword);
config.getNetworkConfig().addAddress(cacheHostName +":"+cachePort);
HazelcastInstance instance = HazelcastClient.newHazelcastClient(config);
return new HazelcastCacheManager(instance);
}
}
<dependencies>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-spring</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-client</artifactId>
<version>3.5</version>
</dependency>
</dependencies>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment