0

我使用https://www.raywenderlich.com/5777183-write-an-aws-lambda-function-with-kotlin-and-micronaut作为指南在 Kotlin 中编写了一个简单的 lambda。我的测试在本地通过。

但是,在将 shadow 生成的 fat jar 上传到 AWS 时,运行时设置为Java 11 (Corretto)并使用处理程序执行它io.micronaut.function.aws.MicronautRequestStreamHandler,我得到以下异常:

No bean of type [io.micronaut.function.LocalFunctionRegistry] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).: io.micronaut.context.exceptions.NoSuchBeanException
io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [io.micronaut.function.LocalFunctionRegistry] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
    at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2290)
    at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:733)
    at io.micronaut.function.executor.StreamFunctionExecutor.execute(StreamFunctionExecutor.java:87)
    at io.micronaut.function.aws.MicronautRequestStreamHandler.handleRequest(MicronautRequestStreamHandler.java:54)

我错过了什么?

项目结构如下:

src
├── main
│   ├── kotlin
│   │   └── com
│   │       └── example
│   │           └── lambda
│   │               └── app
│   │                   ├── AppFunction.kt
│   │                   ├── HandlerInput.kt
│   │                   ├── HandlerOutput.kt
│   │                   └── Service.kt
│   └── resources
│       ├── application.yml
│       └── logback.xml
└── test
    └── kotlin
        └── com
            └── example
                └── lambda
                    └── app
                        ├── AppClient.kt
                        ├── AppFunctionTest.kt
                        └── ServiceTest.kt

重要代码:

// application.yml
micronaut:
  application:
    name: app
data class HandlerInput(var parameters: String)
data class HandlerOutput(val parameters: String, val result: String)
class Service() {
    fun execute(parameters: String): String {
        return "Not yet implemented"
    }
}

@FunctionBean("app")
class AppFunction : Function<HandlerInput, HandlerOutput> {
    private val service: Service = Service()

    override fun apply(input: HandlerInput): HandlerOutput {
        return HandlerOutput(input.parameters, service.execute(input.parameters))
    }
}
// build.gradle as generated by mn
plugins {
    id "org.jetbrains.kotlin.jvm" version "1.4.10"
    id "org.jetbrains.kotlin.kapt" version "1.4.10"
    id "org.jetbrains.kotlin.plugin.allopen" version "1.4.10"
    id "com.github.johnrengelman.shadow" version "6.0.0"
    id "io.micronaut.library" version '1.0.3'
}

micronaut {
    testRuntime "junit5"
    processing {
        incremental true
        annotations "com.example.lambda.app.*"
    }
}

dependencies {
    implementation("io.micronaut:micronaut-validation")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
    implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
    implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
    implementation("io.micronaut:micronaut-runtime")
    implementation("javax.annotation:javax.annotation-api")
    implementation("io.micronaut.aws:micronaut-function-aws")
    runtimeOnly("ch.qos.logback:logback-classic")
    runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")
    // Following dependencies are additions
    // I removed micronaut-http-client testImplementation as it wasn't needed
    testImplementation("io.micronaut:micronaut-function-client")
    testImplementation("io.kotest:kotest-assertions-core:4.3.0")
    testRuntimeOnly("io.micronaut:micronaut-http-server-netty")
    testRuntimeOnly("io.micronaut:micronaut-function-web")
}

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(11)
    }
}

compileKotlin {
    kotlinOptions {
        jvmTarget = '11'
    }
}
compileTestKotlin {
    kotlinOptions {
        jvmTarget = '11'
    }
}
4

0 回答 0