spring-native
0.10.0-SNAPSHOT
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
${classifier}
${builder}
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
<BP_NATIVE_IMAGE_BUILD_ARGUMENTS>${native.build.args}</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
IF_NOT_PRESENT
org.springframework.experimental
spring-aot-maven-plugin
0.10.0-SNAPSHOT
test-generate
test-generate
generate
generate
- 上述pom.xml有以下几处需要注意:
-
插件仓库、依赖库仓库、依赖库版本的配置都集中在这里;
-
配置好spring-aot-maven-plugin和spring-boot-maven-plugin这两个插件,子工程会用到;
-
spring-boot-maven-plugin插件制作docker镜像的时候,又会用到dmikusa/graalvm-tiny镜像,这才是真正构建native image的工具;
新建springboot类型的maven子工程
- 新建名为webmvc的子工程,pom.xml内容如下,可见内容很简单,就是常规依赖库和父工程配置的两个插件,一个负责执行AOT,一个负责构建镜像:
<project xmlns=“http://maven.apache.org/POM/4.0.0”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”>
spring-native-tutorials
com.bolingcavalry
1.0-SNAPSHOT
4.0.0
webmvc
org.springframework.experimental
spring-native
org.springframework.boot
spring-boot-starter-web
org.apache.tomcat.embed
tomcat-embed-core
org.apache.tomcat.embed
tomcat-embed-websocket
org.apache.tomcat.experimental
tomcat-embed-programmatic
${tomcat.version}
org.springframework.boot
spring-boot-starter-test
test
org.springframework.experimental
spring-aot-maven-plugin
true
org.springframework.boot
spring-boot-maven-plugin
- 代码很简单,一个普通的springboot应用,带http接口:
package com.bolingcavalry.webmvc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
@SpringBootApplication
@RestController
public class WebmvcApplication {
pub