Spring boot maven plugin - BOOT-INF 目录导致 AWS Lambda 应用程序失败



SpringBoot 2.1.0.RELEASE中生成的包结构(如果您提取 uberjar文件(发生了变化。

1.5.9.RELEASEjar文件包含comlibMETA-INForg目录

2.1.0.RELEASE有一个BOOT-INFMETA-INForg目录

基本上从2.0.0.RELEASE开始 - 所有的类和库都在BOOT-INF目录中。

因此,当您尝试在Amazon Lambda上运行Spring Boot项目时,它说找不到一个jar,因为它无法读取新的Spring Boot Uberjar结构

我的问题:

  • 在较新版本的 Spring Boot Maven 插件中,是否可以生成与版本 1.5.9.RELEASE 中结构相同的 uber jar?

我尝试了maven-shade-plugin- 但这会导致其他问题。任何帮助,不胜感激。

来自 StackOverflow 的参考链接:Spring Boot Maven 插件 - 没有 BOOT-INF 目录

这个 maven 插件 XML 片段为我做了这个技巧:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>zip-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>${project.artifactId}-${project.version}</finalName>
<descriptors>
<descriptor>src${file.separator}assembly${file.separator}bin.xml</descriptor>
</descriptors>
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>

此外,您还需要一个包含以下内容的assembly/bin.xml文件:

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>lambda-package</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<!-- copy runtime dependencies with some exclusions -->
<fileSet>
<directory>${project.build.directory}${file.separator}lib</directory>
<outputDirectory>lib</outputDirectory>
<excludes>
<exclude>tomcat-embed*</exclude>
</excludes>
</fileSet>
<!-- copy all classes -->
<fileSet>
<directory>${project.build.directory}${file.separator}classes</directory>
<includes>
<include>**</include>
</includes>
<outputDirectory>${file.separator}</outputDirectory>
</fileSet>
</fileSets>
</assembly>

请注意,您必须使用生成的.zip文件,而不是.jar文件。

将 Spring Boot 2 与 Lambda 配合使用的完整工作示例可从 awslabs 获得: https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/springboot2/pet-store

除了@balster答案:

就我而言,我不需要 maven-dependency-plugin。

我的pom.xml插件部分包含:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<descriptors>
<descriptor>src/assembly/bin.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

这是我的垃圾桶.xml内容

<id>lambda</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
<unpack>false</unpack>
<excludes>
<exclude>${artifact}</exclude>
</excludes>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.directory}${file.separator}classes</directory>
<includes>
<include>**</include>
</includes>
<outputDirectory>${file.separator}</outputDirectory>
</fileSet>
</fileSets>
</assembly>

唯一缺少的部分是带有pom文件(xml/properties(的maven文件夹。但它在没有它的情况下运行。

最新更新