当前位置:   article > 正文

升级springboot2.7.10问题汇总_caused by: java.lang.classnotfoundexception: io.mi

caused by: java.lang.classnotfoundexception: io.micrometer.core.instrument.b

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

  1. <dependency>
  2. <groupId>io.springfox</groupId>
  3. <artifactId>springfox-boot-starter</artifactId>
  4. <version>${swagger.version}</version>
  5. <exclusions>
  6. <exclusion>
  7. <groupId>io.springfox</groupId>
  8. <artifactId>springfox-swagger-ui</artifactId>
  9. </exclusion>
  10. <exclusion>
  11. <groupId>io.springfox</groupId>
  12. <artifactId>springfox-swagger2</artifactId>
  13. </exclusion>
  14. </exclusions>
  15. </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文件增加

  1. import org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties;
  2. import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
  3. import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
  4. import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
  5. import org.springframework.boot.actuate.endpoint.web.*;
  6. import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointsSupplier;
  7. import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier;
  8. import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping;
  9. import org.springframework.core.env.Environment;
  10. import org.springframework.util.StringUtils;
  11. import java.util.ArrayList;
  12. import java.util.Collection;
  13. import java.util.List;
  14. 。中间内容省略
  15. @Bean
  16. public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) {
  17. List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
  18. Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
  19. allEndpoints.addAll(webEndpoints);
  20. allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
  21. allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
  22. String basePath = webEndpointProperties.getBasePath();
  23. EndpointMapping endpointMapping = new EndpointMapping(basePath);
  24. boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
  25. return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping, null);
  26. }
  27. private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {
  28. return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
  29. }

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
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/704144
推荐阅读
相关标签
  

闽ICP备14008679号