公司版本2.3,因为那个log4j漏洞准备升级2.6.2测试下,记录下出现的问题
高版本不允许循环依赖,如果写的时候不太注意,改的时候也要改很多地方,最后决定添加个配置解决
在bootstrap.yml中添加
spring: main: allow-circular-references: true
升级spring boot后,配套的spring cloud,alibaba等框架也要一起升级,会缺少一些依赖导致无法启动
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bootstrap</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-loadbalancer</artifactId> </dependency>
如果有关于websocket的模块,也会报错,修改websocket配置类
@Override public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) { //支持原生websocket连接方式 stompEndpointRegistry.addEndpoint("/ws") //.setAllowedOrigins("*") //原代码 .setAllowedOriginPatterns("*");//跨域 }
最后如果用了knife4j,他也会报错,需要添加配置
spring: mvc: pathmatch: matching-strategy: ant-path-matcher
但如果同时也引用了spring-boot-starter-actuator依赖,那么还需要注入一个bean
/** * 解决springboot升级到2.6.x之后,与spring-boot-starter-actuator同时使用时,knife4j报错问题 * * @param webEndpointsSupplier the web endpoints supplier * @param servletEndpointsSupplier the servlet endpoints supplier * @param controllerEndpointsSupplier the controller endpoints supplier * @param endpointMediaTypes the endpoint media types * @param corsProperties the cors properties * @param webEndpointProperties the web endpoint properties * @param environment the environment * @return the web mvc endpoint handler mapping */ @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 = shouldRegisterLinksMapping(webEndpointProperties, environment, basePath); return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping, null); } /** * shouldRegisterLinksMapping * * @param webEndpointProperties webEndpointProperties * @param environment environment * @param basePath / * @return boolean */ private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) { return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT)); }
关联issue地址 https://gitee.com/xiaoym/knife4j/issues/I4JT89
然后就启动成功了,暂时遇到的问题就这些,先记录下
标签:spring,basePath,boot,param,environment,webEndpointProperties,allEndpoints,log4j From: https://www.cnblogs.com/moerjiana/p/17095869.html