英文:
Adding micronaut serde fails starting application as serverless with lanch class as io.micronaut.function.aws.runtime.MicronautLambdaRuntime
问题
Micronaut serde用于支持GraalVM Native Image上的序列化和反序列化。但在添加后,Lambda出现以下错误:
请求循环失败:解码HTTP响应体时出错:类型[class com.amazonaws.serverless.proxy.model.AwsProxyRequest]没有可用于bean内省。请确保该类已用io.micronaut.core.annotation.Introspected注释。
Micronaut版本 = 3.9.4
我添加了Micronaut serde以支持GraalVM Native Image上的序列化和反序列化。
<dependency>
<groupId>io.micronaut.serde</groupId>
<artifactId>micronaut-serde-jackson</artifactId>
<scope>compile</scope>
</dependency>
以下是我用于创建Lambda函数的命令:
mvn clean package -U -Dpackaging=docker-native -D"exec.mainClass"="io.micronaut.function.aws.runtime.MicronautLambdaRuntime" -D"micronaut.runtime"="lambda" -Pgraalvm -DskipTests
英文:
micronaut serde to support serialization and deserialization on GraalVM Native Image. But after adding it the lambda stopped working with below error :
Request loop failed with: Error decoding HTTP response body: No bean introspection available for type [class com.amazonaws.serverless.proxy.model.AwsProxyRequest]. Ensure the class is annotated with io.micronaut.core.annotation.Introspected
Micronaut Version = 3.9.4
I added micronaut serde to support serialization and deserialization on GraalVM Native Image.
<dependency>
<groupId>io.micronaut.serde</groupId>
<artifactId>micronaut-serde-jackson</artifactId>
<scope>compile</scope>
</dependency>
<annotationProcessorPaths combine.self="override">
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.4.1.Final</version>
</path>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject-java</artifactId>
<version>${micronaut.version}</version>
</path>
<path>
<groupId>io.micronaut.data</groupId>
<artifactId>micronaut-data-processor</artifactId>
<version>${micronaut.data.version}</version>
</path>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-graal</artifactId>
<version>${micronaut.version}</version>
</path>
<path>
<groupId>io.micronaut.serde</groupId>
<artifactId>micronaut-serde-processor</artifactId>
<version>1.5.3</version>
</path>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-http-validation</artifactId>
<version>${micronaut.version}</version>
</path>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-validation</artifactId>
<version>${micronaut.version}</version>
</path>
<path>
<groupId>io.micronaut.openapi</groupId>
<artifactId>micronaut-openapi</artifactId>
<version>${micronaut.openapi.version}</version>
</path>
<path>
<groupId>io.micronaut.security</groupId>
<artifactId>micronaut-security-annotations</artifactId>
<version>${micronaut.security.version}</version>
</path>
</annotationProcessorPaths>
But after adding it the lambda stopped working with below error :
Request loop failed with: Error decoding HTTP response body: No bean introspection available for type [class com.amazonaws.serverless.proxy.model.AwsProxyRequest]. Ensure the class is annotated with io.micronaut.core.annotation.Introspected
I am using following command to create lambda function
mvn clean package -U -Dpackaging=docker-native -D"exec.mainClass"="io.micronaut.function.aws.runtime.MicronautLambdaRuntime" -D"micronaut.runtime"="lambda" -Pgraalvm -DskipTestsclear
答案1
得分: 2
因为 com.amazonaws.serverless.proxy.model.AwsProxyRequest
是外部类(定义在这里),您需要像这样将其导入到您的应用程序中:
@SerdeImport(AwsProxyRequest.class)
在Java应用程序中,可以在 Application.java
中这样做:
import io.micronaut.runtime.Micronaut;
import io.micronaut.serde.annotation.SerdeImport;
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
@SerdeImport(AwsProxyRequest.class)
public class Application {
public static void main(String[] args) {
Micronaut.run(Application.class, args);
}
}
在Kotlin应用程序中,可以在 ApplicationKt
中这样做:
@SerdeImport(AwsProxyRequest::class)
object MyTestApp // 需要一个对象来注解
fun main(args: Array<String>) {
run(*args)
}
请注意,您可能需要使用 @SerdeImport
导入更多的类,直到这个错误消失。
如果无法在您的应用程序中使用 micronaut-serde-jackson
,那么您将不得不切换到:
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-jackson-databind</artifactId>
<scope>runtime</scope>
</dependency>
文档:启用外部类的序列化
英文:
Because
com.amazonaws.serverless.proxy.model.AwsProxyRequest
is an external class (definition is here), you'll need to import it into your app like this
@SerdeImport(AwsProxyRequest.class)
In a Java app, this will be done in Application.java
like this:
import io.micronaut.runtime.Micronaut;
import io.micronaut.serde.annotation.SerdeImport;
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
@SerdeImport(AwsProxyRequest.class)
public class Application {
public static void main(String[] args) {
Micronaut.run(Application.class, args);
}
}
In a Kotlin app, this will be done in ApplicationKt
like this:
@SerdeImport(AwsProxyRequest::class)
object MyTestApp // needs an object to annotate
fun main(args: Array<String>) {
run(*args)
}
Please note that you may have to import more classes using @SerdeImport
until this error is gone.
It may also be the case that it is not possible to use micronaut-serde-jackson
with your app, then you'll have to switch to
<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-jackson-databind</artifactId>
<scope>runtime</scope>
</dependency>
答案2
得分: 0
使用Serdable
注解来标记AwsProxyRequest
类。这样它就可以正常工作。
@Serdable
public class AwsProxyRequest {}
英文:
Annotate class AwsProxyRequest
with Serdable
. That way it will work.
@Serdeable
public class AwsProxyRequest {}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论