我是Ignite的新手,实际上是使用spring boot应用程序与ignite进行交互。我已经将缓存摄入了点燃并通过键点燃了缓存。但是如果我尝试通过查询API获取缓存,我会得到以下异常。
[16:56:55,225][SEVERE][http-nio-8080-exec-2][[dispatcherServlet]] Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is javax.cache.CacheException: Indexing is disabled for cache: testCache. Use setIndexedTypes or setTypeMetadata methods on CacheConfiguration to enable.] with root cause javax.cache.CacheException: Indexing is disabled for cache: testCache. Use setIndexedTypes or setTypeMetadata methods on CacheConfiguration to enable.
以下是我的实施代码:
当我调用此方法时,我得到上述异常
@RequestMapping(value = "/query/cache", produces = "text/html")
private String queryCache(Model model) {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
// Load cache with data from the database.
CacheConfiguration<Long, IgnitePerson> cfg = new CacheConfiguration<>("testCache");
IgniteCache<Long, IgnitePerson> cache = ignite.getOrCreateCache(cfg);
SqlQuery<Long, IgnitePerson> query = new SqlQuery<>(IgnitePerson.class, "select * from IgnitePerson");
List<Entry<Long, IgnitePerson>> list = cache.query(query).getAll();
personsList = new ArrayList<>();
for (Entry<Long, IgnitePerson> entry : list) {
personsList.add(entry.getValue());
}
model.addAttribute("persons", personsList);
}
return "cacheresults";
}
这很好,我从点燃
获得缓存@RequestMapping(value = "/read/cache", produces = "text/html")
private String readCache(Model model) {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
// Load cache with data from the database.
CacheConfiguration<Long, IgnitePerson> cfg = new CacheConfiguration<>("testCache");
IgniteCache<Long, IgnitePerson> cache = ignite.getOrCreateCache(cfg);
Set<Long> keys = new TreeSet<>();
keys.add((long) 1);
keys.add((long) 2);
Map<Long, IgnitePerson> map = cache.getAll(keys);
personsList = new ArrayList<>(map.values());
model.addAttribute("persons", personsList);
}
return "cacheresults";
}
答案 0 :(得分:2)
您没有配置SQL架构和索引 - 如果要运行查询,则需要这样做。有关详细信息,请参阅此页:https://apacheignite.readme.io/docs/sql-queries