首页 > 其他分享 >spring boot 2.6.2解决log4j漏洞

spring boot 2.6.2解决log4j漏洞

时间:2023-02-06 16:45:21浏览次数:50  
标签:spring basePath boot param environment webEndpointProperties allEndpoints log4j

公司版本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

相关文章

  • SpringBoot数据分页工具类
    SpringBoot数据分页工具类/***数据分页工具*/publicclassPageUtil{publicstaticPagepageHelp(@NotNullIntegerpageNum,@NotNullIntegerpageSize,@No......
  • Spring13 - 自动注入@Autowired
    @Autowired注入单独使用@Autowired注解,默认根据类型装配。【默认是byType】查看源码:packageorg.springframework.beans.factory.annotation;importjava.lang.annota......
  • Spring init-method与destroy-method属性的用法解析
    目录springinit-method与destroy-method属性使用知识点介绍:操作步骤:init-method="init"和destroy-method="close"作用 Springinit-method与destroy-method......
  • Spring与Web环境集成
    ApplicationContext应用上下文获取方式初步设想代码示例:<!--pom.xml配置文件--><dependencies> <dependency> <groupId>org.springframework</groupId> <artifactI......
  • org.springframework.web.bind.MissingServletRequestParameterException: Required r
    这个错可能是后端请求方式和对应的注解使用错误也有可能是你前端的请求路径enterpriseId这个写错后端 方法1.@RequestParam:required()defaulttrue;===>设置@Req......
  • Spring12 - 注解管理bean
    Annotation从Java5开始,Java增加了对注解(Annotation)的支持,它是代码中的一种特殊标记,可以在编译、类加载和运行时被读取,执行相应的处理。开发人员可以通过注解在不改变......
  • Spring:声明式事务
    目录JdbcTemplate简介准备①加入依赖②创建jdbc.properties③配置Spring的配置文件测试①在测试类装配JdbcTemplate②测试增删改功能③查询一条数据为实体类对象④查询多......
  • SpringBoot-超大文件上传-如何上传文件-大文件上传
    ​ 需求:项目要支持大文件上传功能,经过讨论,初步将文件上传大小控制在500M内,因此自己需要在项目中进行文件上传部分的调整和配置,自己将大小都以501M来进行限制。 第一步......
  • Spring9 - bean生命周期
    ②修改类UserpublicclassUser{privateIntegerid;privateStringusername;privateStringpassword;privateIntegerage;publicUs......
  • Spring10 - FactoryBean
    FactoryBean①简介FactoryBean是Spring提供的一种整合第三方框架的常用机制。和普通的bean不同,配置一个FactoryBean类型的bean,在获取bean的时候得到的并不是class属性中......