springboot升级到jdk21最新教程

springboot升级到jdk21最新教程

一、升级项目

1.1 POM文件

最近很多小伙伴私信我要我出一个springboot搭配jdk21的教程,应粉丝要求,我去spring官网找到了springboot和jdk版本的是配图,供大家参考!之前博主写的springboot 3.0.0 搭配jdk20不知道各位小伙伴们有没有看过呢?现在jdk21出来了,springboot 3.0.0的版本已经不够用了,需要升级到springboot 3.1.x系列的版本才可以与之匹配。

    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.0</version>
        <relativePath/>
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.***piler.encoding>UTF-8</maven.***piler.encoding>
        <maven.***piler.source>21</maven.***piler.source>
        <maven.***piler.target>21</maven.***piler.target>
        <maven.***piler.***pilerVersion>21</maven.***piler.***pilerVersion>
        <java.version>21</java.version>
        <skipTests>true</skipTests>
    </properties>

1.2 Lombok问题

如果你的项目中有使用Lombok,并且版本呢是1.18.28,可能会出现这个问题,这是因为此版本并不支持jdk21,需要升级到1.18.30。

java: java.lang.NoSuchFieldError: Class ***.sun.tools.javac.tree.JCTree$JCImport does not have member field '***.sun.tools.javac.tree.JCTree qualid'
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.30</version>
    <scope>provided</scope>
</dependency>

二、制作docker镜像

2.1 dockerfile文件

FROM alpine:3.15

ARG version=21.0.0.34.1

# Please note that the THIRD-PARTY-LICENSE could be out of date if the base image has been updated recently.
# The Corretto team will update this file but you may see a few days' delay.
RUN wget -O /THIRD-PARTY-LICENSES-20200824.tar.gz https://corretto.aws/downloads/resources/licenses/alpine/THIRD-PARTY-LICENSES-20200824.tar.gz && \
    echo "82f3e50e71b2aee21321b2b33de372feed5befad6ef2196ddec92311bc09becb  /THIRD-PARTY-LICENSES-20200824.tar.gz" | sha256sum -c - && \
    tar x -ovzf THIRD-PARTY-LICENSES-20200824.tar.gz && \
    rm -rf THIRD-PARTY-LICENSES-20200824.tar.gz && \
    wget -O /etc/apk/keys/amazoncorretto.rsa.pub https://apk.corretto.aws/amazoncorretto.rsa.pub && \
    SHA_SUM="6cfdf08be09f32ca298e2d5bd4a359ee2b275765c09b56d514624bf831eafb91" && \
    echo "${SHA_SUM}  /etc/apk/keys/amazoncorretto.rsa.pub" | sha256sum -c - && \
    echo "https://apk.corretto.aws" >> /etc/apk/repositories && \
    apk add --no-cache amazon-corretto-21=$version-r0 && \
    rm -rf /usr/lib/jvm/java-21-amazon-corretto/lib/src.zip


ENV LANG C.UTF-8

ENV JAVA_HOME=/usr/lib/jvm/default-jvm
ENV PATH=$PATH:/usr/lib/jvm/default-jvm/bin

2.2 构建镜像命令

docker build -t openjdk:21-jdk-alpine .
转载请说明出处内容投诉
CSS教程_站长资源网 » springboot升级到jdk21最新教程

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买