我正在尝试做一个简单的kotlin + dropwizard应用程序。
我关注了一些在线信息,包括此https://dev.to/tagmg/step-by-step-guide-to-building-web-api-with-kotlin-and-dropwizard
因此,在进行了一些修改之后,我创建了一个带有build.gradle.kts的应用程序,如下所示:
plugins {
application
kotlin("jvm")
id("com.github.johnrengelman.shadow") version "4.0.3"
}
application {
mainClassName = "path.MyApplication"
}
dependencies {
implementation("... dependencies ...")
}
val shadowJar: ShadowJar by tasks
shadowJar.apply {
mergeServiceFiles()
manifest.attributes.apply {
put("Main-Class", application.mainClassName)
}
}
tasks.named<JavaExec>("run") {
args("server", "local.yml")
}
在MyApplication中,我有这样的东西:
MyApplication类:Application(){
companion object {
@JvmStatic fun main(args: Array<String>) {
MyApplication().run(*args)
}
}
override fun run(configuration: MyConfiguration, environment: Environment) {
val myResource = MyResource() //endpoints with dropwizard
environment.jersey().register(myResource)
}
}
在MyConfiguration上
class MyConfiguration(val serviceName: String
) : Configuration(){
}
问题...
当我执行gradlew运行时,出现此错误:
* Failed to parse configuration; Cannot construct instance of `MyConfiguration` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: UNKNOWN; line: -1, column: -1]
我真的不知道为什么出现此错误,或者我的local.yml中是否有错误
我的local.yml文件具有以下内容:
serviceName: Kotlin Calculator
具有讽刺意味的是,当我更改=时,我的应用程序将运行。
任何想法这可能是什么问题吗?
答案 0 :(得分:1)
MyConfiguration
类应具有一个空的构造函数。将serviceName设为属性。
class MyConfiguration() : Configuration(){
@NotNull
val serviceName: String = ""
}