第 2 章 以嵌入式模式运行
在项目中嵌入 Data Grid 库,以进行内存数据存储。
2.1. 添加 EmbeddedCacheManager Bean 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
将
infinispan-spring-boot-starter-embedded添加到项目的 classpath 中,以启用 Embedded 模式。默认情况下,这个入门程序在 Remote Client/Server 模式下运行,在 classpath 上带有
infinispan-spring-boot-starter-remote。使用 Spring
@Autowired注解在 Java 配置类中包含EmbededCacheManagerbean,如下例所示:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 现在,您可以以嵌入式模式使用 Data Grid。以下是一个简单的示例:
cacheManager.getCache("testCache").put("testKey", "testValue"); System.out.println("Received value from cache: " + cacheManager.getCache("testCache").get("testKey"));cacheManager.getCache("testCache").put("testKey", "testValue"); System.out.println("Received value from cache: " + cacheManager.getCache("testCache").get("testKey"));Copy to Clipboard Copied! Toggle word wrap Toggle overflow