项目中遇到一个需求,需要把数据缓存起来,并且方便查询。经老同事的介绍,决定尝试一下apache ignite
。
项目依赖
<properties>
<ignite.version>2.9.0</ignite.version>
<h2.version>1.4.197</h2.version>
</properties>
// 省略
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-core</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-indexing</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-log4j</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring-data_2.2</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
写了以下代码进行启动测试。
fun initial() {
val cache = Ignition.ignite().cache<String, ImportStage>("ImportStage")
cache.clear()
}
fun main() {
val cfg = IgniteConfiguration()
cfg.gridLogger = Log4JLogger()
val ignite = Ignition.start(cfg)
val cacheCfg = CacheConfiguration<String, ImportStage>("ImportStage")
cacheCfg.cacheMode = CacheMode.PARTITIONED; // Default.
cacheCfg.setIndexedTypes(String::class.java, ImportStage::class.java)
ignite.getOrCreateCache(cacheCfg)
initial()
}
一开始h2的版本使用最新的1.4.200
会报以下错误
Caused by: org.h2.jdbc.JdbcSQLNonTransientConnectionException: Unsupported connection setting "MULTI_THREADED" [90113-200]
找到别人的教程,把h2版本降级后启动成功。
网友评论