是否可以在Ktor的应用程序中使用ObjectBox?我有以下 build.gradle 文件:
buildscript {
// Consider moving these values to `gradle.properties`
ext.kotlin_version = '1.2.70'
ext.ktor_version = '0.9.4'
ext.appengine_version = '1.9.60'
ext.appengine_plugin_version = '1.3.4'
ext.objectbox_version = '2.1.0'
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.cloud.tools:appengine-gradle-plugin:$appengine_plugin_version"
classpath "io.objectbox:objectbox-gradle-plugin:$objectbox_version"
}
}
apply plugin: 'kotlin'
apply plugin: 'war'
apply plugin: 'com.google.cloud.tools.appengine'
// to enable gradle in IntelliJ IDEA
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.objectbox'
sourceSets {
main.kotlin.srcDirs = [ 'src/main/kotlin' ]
}
repositories {
jcenter()
maven { url "https://kotlin.bintray.com/ktor" }
maven { url "https://dl.bintray.com/kotlin/exposed" }
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "io.ktor:ktor-server-servlet:$ktor_version"
compile "io.ktor:ktor-html-builder:$ktor_version"
compile "io.ktor:ktor-gson:$ktor_version"
compile "io.ktor:ktor-freemarker:$ktor_version"
compile 'org.jetbrains.exposed:exposed:0.8.5'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.12'
providedCompile "com.google.appengine:appengine:$appengine_version"
}
kotlin.experimental.coroutines = 'enable'
task run(dependsOn: appengineRun)
起初,项目运行成功。那时我有模型课:
class User()
但是当我在类中添加了两个注释-@Entity
包中的@Id
和io.objectbox.annotation
时:
@Entity
class User(@Id val id: Long)
发生错误:java.lang.reflect.UndeclaredThrowableException
。尽管有错误,ObjectBox仍使用MyObjectBox
生成了代码:
此错误的原因是什么?而且我知道大多数ObjectBox被认为是移动设备的数据库。那么是否有可能在与Ktor一起使用的应用程序中将ObjectBox用作数据库?