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不兼容问题
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