在 lambda aws 测试期间,抛出 class not found 异常

During lambda aws test, a class not found exception is thrown

Serverless Functions with Spring Cloud Functions 是我使用的 Baeldung 文章。我更改了他们推荐的 aws-adapter 依赖项,因为在 maven 中导入失败,所以我找到了版本 3.0.1.RELEASE 并改用它。所有错误都消失了,我将项目上传为 .jar 文件。我尝试了 "maven package" 和 "maven clean shade" 命令来创建一个 .jar 文件并直接上传到 lambda 函数。我按照他们的说明在 lambda 函数中指定处理程序。有谁知道我可能 运行 陷入这个问题的任何其他原因。

 java.lang.ClassNotFoundException: package.MyStringHandlers
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
{
  "errorMessage": "Class not found: package.MyStringHandlers",
  "errorType": "java.lang.ClassNotFoundException"
}
<dependencies>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-lambda-java-events</artifactId>
            <version>2.0.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-lambda-java-core</artifactId>
            <version>1.1.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot.experimental/spring-boot-thin-layout -->
        <dependency>
            <groupId>org.springframework.boot.experimental</groupId>
            <artifactId>spring-boot-thin-layout</artifactId>
            <version>1.0.23.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-function-web</artifactId>
            <version>1.0.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-function-adapter-aws</artifactId>
            <version>3.0.1.RELEASE</version>
        </dependency>


    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <configuration>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                    <shadedArtifactAttached>true</shadedArtifactAttached>
                    <shadedClassifierName>aws</shadedClassifierName>
                </configuration>
            </plugin>
        </plugins>
    </build>
        </project>

您似乎同时使用了一些混合且不兼容的函数版本 1.0.1.RELEASE 和 3.0.1.RELEASE 尽管您的问题可能无关紧要,但如果没有看到您的代码就无法判断。

好消息是:

对于 3.0.1 版本,我们只是添加了一个 Getting Started guide which takes you step by step. We've also updated the example,它也在入门中引用。有了它,您应该会在 5-10 分钟内起床 运行。