Apache Ignite 异常 - 无法初始化缓存存储(未提供数据源)
Apache Ignite Exception - Failed to initialize cache store (data source is not provided)
我正在尝试为我的 ignite 缓存实现持久存储,我正在使用 CacheJdbcPojoStoreFactory,我的缓存存储工厂初始化如下所示
@Autowired
DataSorce datasource;
@Bean
public CacheJdbcPojoStoreFactory<?, ?> cacheJdbcdPojoStorefactory(){
CacheJdbcPojoStoreFactory<?, ?> factory = new CacheJdbcPojoStoreFactory<>();
factory.setDataSource(dataSource);
return factory;
}
我的缓存实现如下所示
CacheConfiguration pesonConfig = new CacheConfiguration();
pesonConfig.setName("personCache");
cacheJdbcdPojoStorefactory.setTypes(jdbcTypes.toArray(new JdbcType[jdbcTypes.size()]));
Collection<QueryEntity> qryEntities = new ArrayList<>();
qryEntities.add(qryEntity);
pesonConfig.setQueryEntities(qryEntities);
pesonConfig.setCacheStoreFactory((Factory<? extends CacheStore<Integer, Person>>) cacheJdbcdPojoStorefactory);
ROCCache<Integer, Person> personCache= rocCachemanager.createCache(pesonConfig);
personCache.put(1, p1);
personCache.put(2, p2)
(我正在传递正确的查询 Entities 和 JdbcTypes ,为简单起见,我没有在此处显示该代码)
但是当我 运行 这段代码时,我得到了下面的堆栈跟踪
Failed to initialize cache store (data source is not provided).
at org.apache.ignite.internal.util.IgniteUtils.startLifecycleAware(IgniteUtils.java:8385)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.createCache(GridCacheProcessor.java:1269)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepareCacheStart(GridCacheProcessor.java:1638)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepareCachesStart(GridCacheProcessor.java:1563)
at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.startCaches(GridDhtPartitionsExchangeFuture.java:944)
at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.init(GridDhtPartitionsExchangeFuture.java:511)
at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.body(GridCachePartitionExchangeManager.java:1297)
at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:110)
at java.lang.Thread.run(Thread.java:745)
Caused by: class org.apache.ignite.IgniteException: Failed to initialize cache store (datasource is not provided). at org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore.start(CacheAbstractJdbcStore.java:297)
at org.apache.ignite.internal.util.IgniteUtils.startLifecycleAware(IgniteUtils.java:8381)
... 8 more
当我调试时,我可以看到我的数据源参数在 cacheJdbcdPojoStorefactory 对象中正确设置。我哪里错了?
无需连接数据源 bean 并将其设置到工厂,您可以提供其 bean ID,工厂将从应用程序上下文中获取它。这是示例:
@Bean
public CacheJdbcPojoStoreFactory<?, ?> cacheJdbcdPojoStorefactory(){
CacheJdbcPojoStoreFactory<?, ?> factory = new CacheJdbcPojoStoreFactory<>();
factory.setDataSourceBean("data-source-bean");
return factory;
}
问题是工厂将被序列化,但数据源字段是瞬态的。这使得 setDataSource()
属性 非常混乱,我认为它应该被弃用并重新设计。
我正在尝试为我的 ignite 缓存实现持久存储,我正在使用 CacheJdbcPojoStoreFactory,我的缓存存储工厂初始化如下所示
@Autowired
DataSorce datasource;
@Bean
public CacheJdbcPojoStoreFactory<?, ?> cacheJdbcdPojoStorefactory(){
CacheJdbcPojoStoreFactory<?, ?> factory = new CacheJdbcPojoStoreFactory<>();
factory.setDataSource(dataSource);
return factory;
}
我的缓存实现如下所示
CacheConfiguration pesonConfig = new CacheConfiguration();
pesonConfig.setName("personCache");
cacheJdbcdPojoStorefactory.setTypes(jdbcTypes.toArray(new JdbcType[jdbcTypes.size()]));
Collection<QueryEntity> qryEntities = new ArrayList<>();
qryEntities.add(qryEntity);
pesonConfig.setQueryEntities(qryEntities);
pesonConfig.setCacheStoreFactory((Factory<? extends CacheStore<Integer, Person>>) cacheJdbcdPojoStorefactory);
ROCCache<Integer, Person> personCache= rocCachemanager.createCache(pesonConfig);
personCache.put(1, p1);
personCache.put(2, p2)
(我正在传递正确的查询 Entities 和 JdbcTypes ,为简单起见,我没有在此处显示该代码) 但是当我 运行 这段代码时,我得到了下面的堆栈跟踪
Failed to initialize cache store (data source is not provided).
at org.apache.ignite.internal.util.IgniteUtils.startLifecycleAware(IgniteUtils.java:8385)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.createCache(GridCacheProcessor.java:1269)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepareCacheStart(GridCacheProcessor.java:1638)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepareCachesStart(GridCacheProcessor.java:1563)
at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.startCaches(GridDhtPartitionsExchangeFuture.java:944)
at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.init(GridDhtPartitionsExchangeFuture.java:511)
at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.body(GridCachePartitionExchangeManager.java:1297)
at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:110)
at java.lang.Thread.run(Thread.java:745)
Caused by: class org.apache.ignite.IgniteException: Failed to initialize cache store (datasource is not provided). at org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore.start(CacheAbstractJdbcStore.java:297)
at org.apache.ignite.internal.util.IgniteUtils.startLifecycleAware(IgniteUtils.java:8381)
... 8 more
当我调试时,我可以看到我的数据源参数在 cacheJdbcdPojoStorefactory 对象中正确设置。我哪里错了?
无需连接数据源 bean 并将其设置到工厂,您可以提供其 bean ID,工厂将从应用程序上下文中获取它。这是示例:
@Bean
public CacheJdbcPojoStoreFactory<?, ?> cacheJdbcdPojoStorefactory(){
CacheJdbcPojoStoreFactory<?, ?> factory = new CacheJdbcPojoStoreFactory<>();
factory.setDataSourceBean("data-source-bean");
return factory;
}
问题是工厂将被序列化,但数据源字段是瞬态的。这使得 setDataSource()
属性 非常混乱,我认为它应该被弃用并重新设计。