aws lambda,带Spring Boot,gradle不工作调用aws lambda函数时类未找到异常

v64noz0r  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(267)

我使用的是spring boot 2.4.8,我已经为aws lambda创建了示例演示。我正在使用构建工具gradle。所以,当我在aws lambda上部署jar时,我收到了类not found exception。
有关参考信息,请参见附加屏幕截图。

下面是我的build.gradle文件

plugins {
    id 'org.springframework.boot' version '2.4.8'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    runtimeOnly 'com.h2database:h2'
    implementation 'org.springframework.cloud:spring-cloud-function-adapter-aws:2.0.1.RELEASE'
    implementation 'com.amazonaws:aws-lambda-java-core:1.2.1'
    implementation 'com.amazonaws:aws-lambda-java-events:2.2.9'
    implementation 'com.google.code.gson:gson:2.8.6'       
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
    useJUnitPlatform()
}

在aws lambda上,我在处理程序中配置了以下值。

com.example.handler.NotificationHandler:handleRequest

下面是我的包结构。

notificationhandler.java文件

package com.example.handler;

import java.util.HashMap;

import org.springframework.stereotype.Component;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

@Component
public class NotificationHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {

    Gson gson = new GsonBuilder().setPrettyPrinting().create();

    @Override
    public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context context) {
        APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent();
        response.setIsBase64Encoded(false);
        response.setStatusCode(200);
        HashMap<String, String> headers = new HashMap<String, String>();
        headers.put("Content-Type", "application/json");
        response.setHeaders(headers);
        response.setBody("{\n"
                + "  \"key1\": \"value1\",\n"
                + "  \"key2\": \"value2\",\n"
                + "  \"key3\": \"value3\"\n"
                + "}");
        // log execution details
        Util.logEnvironment(event, context, gson);
        return response;
    }
}

任何帮助或建议对我都更有帮助。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题