升级springboot2.7.10问题汇总

1.监控组件的不兼容;报错为:Caused by: java.lang.ClassNotFoundException: io.micrometer.core.instrument.binder.jvm.JvmHeapPressureMetrics

 解决办法:io.micrometer:micrometer-core和micrometer-registry-prometheus升级到1.10.5版本即可

2.循环依赖报错问题;The dependencies of some of the beans in the application context form a cycle

解决方式1:

@Autowired 改为 @Resource 

解决方式2:增加配置允许循环依赖

spring.main.allow-circular-references=true

3.配置文件不兼容

3.1请求路由配置

# server.servlet.path=/api --已过期更改为下方配置

server.servlet.context-path=/api

或者改为spring.mvc.servlet.path=/api

3.2日志配置
#logging.path=${app.output}/logs
#logging.name=${logging.path}/app.log更改为下方配置

logging.file.path=${app.output}/logs

logging.file.name=${logging.file.path}/app.log

4.javax.validation:validation-api不兼容,排除掉,引用新的jakarta.validation:jakarta.validation-api

5.swagger2不兼容问题

5.1.swagger报错 参考spring - I am getting this error "Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException" - Stack Overflow

Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

5.1.1去掉springfox-swagger-ui和springfox-swagger2,更改为swagger.version=3.0.0

<dependency>
 <groupId>io.springfox</groupId>
 <artifactId>springfox-boot-starter</artifactId>
 <version>${swagger.version}</version>
 <exclusions>
 <exclusion>
 <groupId>io.springfox</groupId>
 <artifactId>springfox-swagger-ui</artifactId>
 </exclusion>
 <exclusion>
 <groupId>io.springfox</groupId>
 <artifactId>springfox-swagger2</artifactId>
 </exclusion>
 </exclusions>
</dependency>

5.1.2  注意:如果没有用到knife4j,则上一步的exclusions干掉。 如果使用了则将knife4j-version版本升级到3.0.3

5.1.3 配置文件增加

spring.mvc.pathmatch.matching-strategy=ant_path_matcher

5.1.4 SwaggerConfig.java文件增加

import org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
import org.springframework.boot.actuate.endpoint.web.*;
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
 
 
。
。
。中间内容省略
。
。
  
  
@Bean
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) {
    List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
 Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
 allEndpoints.addAll(webEndpoints);
 allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
 allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
 String basePath = webEndpointProperties.getBasePath();
 EndpointMapping endpointMapping = new EndpointMapping(basePath);
 boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
 return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping, null);
}
 
private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {
    return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
}

5.2.报错:Error creating bean with name  ”defaultServletHandlerMapping“  defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]

解决:

# Spring Boot2.4以上版本默认情况下,嵌入式Servlet容器提供的DefaultServlet不再注册。如果应用程序需要要它,需要进行一定的配置
server.servlet.register-default-servlet=true
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值