基础组件版本升级:
jdk由1.8升级到17
spring-boot由2.7.6升级到3.1.2版本
spring-cloud-alibaba由2021.0.4.0升级到2022.0.0.0-RC2版本
maven构建插件里的配置要改为17:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>17</release>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
javax相关的包要改为jakarta:
<!-- 废弃 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<!-- 改为 jakarta.servlet -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</dependency>
Spring Boot3.0已经将依赖项从Java EE迁移到Jakarta EE API(主要是避免Oracle 的版权问题),所以要将项目中的 javax.servlet.* 改为 jakarta.servlet.*
IDEA工具提供了迁移工具,可以较为方便的修改Jakarta
IDEA官方文档:Migrate | IntelliJ IDEA Documentation
log4j需要升级到2.19.0及以上版本:
<!-- log4j升级到2.19.0 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId> ...... </artifactId>
<version>2.19.0</version>
</dependency>
代码层面的一些问题:
1、org.springframework.web.filter.HttpPutFormContentFilter已经被废弃并移除了,可以使用org.springframework.web.filter.FormContentFilter来替代。
FormContentFilter类能够解析PUT和PATCH请求中的表单数据并将其作为请求参数传递给控制器方法。
// 如果之前过滤器配置了HttpPutFormContentFilter
@Bean
public FilterRegistrationBean<Filter> HttpPutFormContentFilter() {
FilterRegistrationBean<Filter> registrationBean = new FilterRegistrationBean<Filter>();
registrationBean.setFilter(new HttpPutFormContentFilter());
registrationBean.addUrlPatterns("/*");
registrationBean.setOrder(2);
return registrationBean;
}
// 改成FormContentFilter
// FormContentFilter类能够解析PUT和PATCH请求中的表单数据并将其作为请求参数传递给控制器方法
@Bean
public FilterRegistrationBean<Filter> FormContentFilter() {
FilterRegistrationBean<Filter> registrationBean = new FilterRegistrationBean<Filter>();
registrationBean.setFilter(new FormContentFilter());
registrationBean.addUrlPatterns("/*");
registrationBean.setOrder(2);
return registrationBean;
}
2、org.springframework.web.servlet.handler.HandlerInterceptorAdapter已经被废弃并移除了,可以使用org.springframework.web.servlet.handler.HandlerInterceptor接口来替代。
@Component
public class CustomInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
HandlerInterceptor.super.preHandle(request, response, handler);
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
}
}
3、编译错误:
无法将类 org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping中的构造器 WebMvcEndpointHandlerMapping应用到给定类型;
WebMvcEndpointHandlerMapping构造方法是6个参数,检查一下,不要少传或多传了。
4、编译错误:
对于ServletRegistrationBean(com.alibaba.druid.support.http.StatViewServlet,java.lang.String), 找不到合适的构造器
druid版本升级到1.2.18,com.alibaba.druid.support.http.StatViewServlet 改为 com.alibaba.druid.support.jakarta.StatViewServlet
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.18</version>
</dependency>
5、编译错误:
不兼容的类型: com.alibaba.druid.support.http.WebStatFilter无法转换为jakarta.servlet.Filter
同上,druid版本升级到1.2.18,com.alibaba.druid.support.http.WebStatFilter 改为 com.alibaba.druid.support.jakarta.WebStatFilter
6、mybatis版本问题:
java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException
需要升级mybatis的版本 ,对应版本如下:文章来源:https://www.toymoban.com/news/detail-786149.html
文章来源地址https://www.toymoban.com/news/detail-786149.html
到了这里,关于springboot升级到3.x + jdk升级到17的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!