Last active
November 28, 2016 14:24
-
-
Save slaskawi/d830721c58d3afafc4f22be6f0916435 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @SpringBootApplication | |
| public class SpringBootApp { | |
| private static final String CACHE_NAME = "test"; | |
| private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | |
| /** | |
| * This bean is optional but it shows how to inject {@link org.infinispan.configuration.global.GlobalConfiguration}. | |
| */ | |
| @Bean | |
| public InfinispanGlobalConfigurer globalConfiguration() { | |
| logger.info("Defining Global Configuration"); | |
| return () -> GlobalConfigurationBuilder | |
| .defaultClusteredBuilder() | |
| .globalJmxStatistics().allowDuplicateDomains(true) | |
| .build(); | |
| } | |
| /** | |
| * Here we inject {@link Configuration}. | |
| */ | |
| @Bean | |
| public InfinispanCacheConfigurer cacheConfigurer() { | |
| logger.info("Defining {} configuration", CACHE_NAME); | |
| return manager -> { | |
| Configuration ispnConfig = new ConfigurationBuilder() | |
| .clustering().cacheMode(CacheMode.DIST_SYNC) | |
| .build(); | |
| manager.defineConfiguration(CACHE_NAME, ispnConfig); | |
| }; | |
| } | |
| public static void main(String[] args) { | |
| ApplicationContext ctx = SpringApplication.run(SpringBootApp.class, args); | |
| EmbeddedCacheManager cacheManager = ctx.getBean(EmbeddedCacheManager.class); | |
| Cache<Long, String> cache = cacheManager.getCache(CACHE_NAME); | |
| cache.put(System.currentTimeMillis(), "Infinispan"); | |
| logger.info("Values from Cache: {}", cache.entrySet()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment