dmikusa/graalvm-tiny
spring-release
Spring release
https://repo.spring.io/release
false
spring-milestone
Spring milestone
https://repo.spring.io/milestone
false
spring-snapshot
Spring Snapshots
https://repo.spring.io/snapshot
false
spring-release
Spring release
https://repo.spring.io/release
false
spring-milestone
Spring milestone
https://repo.spring.io/milestone
false
spring-snapshot
Spring Snapshots
https://repo.spring.io/snapshot
false
org.springframework.experimental
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}
IF_NOT_PRESENT
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的工具;
- 新建名为webmvc的子工程,pom.xml内容如下,可见内容很简单,就是常规依赖库和父工程配置的两个插件,一个负责执行AOT,一个负责构建镜像:
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 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 { public static void main(String[] args) { SpringApplication.run(WebmvcApplication.class, args); } @ResponseStatus(HttpStatus.ACCEPTED) @GetMapping(“/status”) public String status() { return “status”; } @GetMapping(“/”) public String hello() { return "1. Hello from Spring MVC and Tomcat, " + LocalDateTime.now(); } } mvn clean -U -DskipTests spring-boot:build-image … [INFO] Successfully built image ‘docker.io/library/webmvc:1.0-SNAPSHOT’ [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary for spring-native-tutorials 1.0-SNAPSHOT: [INFO] [INFO] spring-native-tutorials … SUCCESS [ 1.786 s] [INFO] webmvc … SUCCESS [04:19 min] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 04:25 min [INFO] Finished at: 2021-05-22T16:36:44+08:00 [INFO] ------------------------------------------------------------------------ [WARNING] The requested profile “nexus” could not be activated because it does not exist. (base) zhaoqindeMBP:~ zhaoqin$ docker history webmvc:1.0-SNAPSHOT IMAGE CREATED CREATED BY SIZE COMMENT b8ff54813ae0 41 years ago 69B 41 years ago 452kB 41 years ago 2.51MB 41 years ago 57.2MB 41 years ago 1.4MB 41 years ago 268B 41 years ago 17.3MB docker run --rm -p 8080:8080 webmvc:1.0-SNAPSHOT
[](()验证



