java1.8升级Java17踩坑记录

引言

在Java的发展历程中,Java 17是一个重要的里程碑,作为长期支持(LTS)版本,它带来了许多新特性和性能改进。然而,从Java 1.8直接升级到Java 17并不是一件简单的事情,过程中可能会遇到各种兼容性问题和意想不到的坑。本文将记录在升级过程中遇到的一些常见问题及其解决方案。

1. maven编译报错

错误提示 无效的目标发行版: 17 具体原因截图如下

 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project work-order-common: Fatal error compiling: 无效的目标发行版: 17 -> [Help 1]

解决
1。配置jdk17 环境变量
2。升级maven版本 建议3.8以上
3。项目设置 确保为 jdk17
在这里插入图片描述

4。jave compiler 版本 确认为17
在这里插入图片描述

2、lombok 编译报错

java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x690e4b00) cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module @0x690e4b00

原因:JDK版本太高,lombok版本太低。
解决方法:升级lombok版本从1.18.12到1.18.28(最新版本)

3. 项目启动报错


***************************
APPLICATION FAILED TO START
***************************

Description:

No spring.config.import property has been defined

Action:

Add a spring.config.import=nacos: property to your configuration.
	If configuration is not required add spring.config.import=optional:nacos: instead.
	To disable this check, set spring.cloud.nacos.config.import-check.enabled=false.

Disconnected from the target VM, address: '127.0.0.1:50241', transport: 'socket'

Process finished with exit code 1

由于项目中使用springcloud alibaba 组件 nacos 需要在bootstrap文件中优先加载
Spring Cloud 新版本默认将 Bootstrap 禁用,需要将 spring-cloud-starter-bootstrap 依赖引入到工程中:

 <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
 </dependency>

4. spring cloud commons 中 okhttp报错

2023-06-09 17:06:03.714 ERROR [main] [,,,] org.springframework.boot.SpringApplication.reportFailure - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'okHttpClientBuilder' defined in class path resource [org/springframework/cloud/commons/httpclient/HttpClientConfiguration$OkHttpClientConfiguration.class
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值