maven - Spring Boot maven 插件 - 导致 AWS Lambda 应用程序失败的 BOOT-INF 目录
问题描述
SpringBoot 2.1.0.RELEASE中生成的包结构(如果您提取 uber jar文件)发生了变化。
1.5.9.RELEASE jar 文件有com
、lib
、META-INF
和org
目录
2.1.0.RELEASE有一个BOOT-INF
,META-INF
和org
目录
基本上从2.0.0.RELEASE开始——所有的类和库都在BOOT-INF
目录中。
因此 - 当您尝试在Amazon Lambda上运行 Spring Boot 项目时- 它说找不到jar,因为它无法读取新的 Spring Boot Uber jar 结构
我的问题:
- 是否可以在较新版本的 Spring Boot Maven 插件中生成与 1.5.9.RELEASE 版本相同的结构的 uber jar?
我尝试了maven-shade-plugin
- 但这会导致其他问题。任何帮助表示赞赏。
来自 StackOverflow 的参考链接:Spring Boot Maven Plugin - No BOOT-INF directory
解决方案
这段 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
文件。
awslabs 提供了将 Spring Boot 2 与 Lambda 结合使用的完整工作示例:https ://github.com/awslabs/aws-serverless-java-container/tree/master/samples/springboot2/pet-store
推荐阅读
- reactjs - 为什么我的网站要求访问 Firefox 中的 VR 设备?
- python - Tkinter:如何以及最佳实践来访问框架外的功能?
- jquery - 如何逐个淡入元素,但是当我滚动到它们时?
- bash - Bash 脚本删除除选定文件之外的所有文件
- python - 有没有办法在python中计算每周数据?
- c# - ContextMenu 在打开后立即消失/关闭
- javascript - 如何使图像固定在屏幕上,但可见区域仍然滚动
- javascript - 如何将 1 添加到 MongoDB 中的值?
- r - R中的重复值与不同的data.frames
- python - 如何搜索列表打印或返回匹配的项目?