Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException 转载哈!!

发布时间 2023-09-03 23:10:09作者: mljqqh

2023-09-03 22:53:53.622 WARN 20788 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException:

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

 

 

    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    //下面的代码都是解决异常的
    // TODO: 2023/8/19 研究下下面这个配置是什么玩意

    //下面的代码都是解决异常的
    @Bean
    public static BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() {
        return new BeanPostProcessor() {

            @Override
            public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
                if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) {
                    customizeSpringfoxHandlerMappings(getHandlerMappings(bean));
                }
                return bean;
            }

            private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings(List<T> mappings) {
                List<T> copy = mappings.stream()
                        .filter(mapping -> mapping.getPatternParser() == null)
                        .collect(Collectors.toList());
                mappings.clear();
                mappings.addAll(copy);
            }

            @SuppressWarnings("unchecked")
            private List<RequestMappingInfoHandlerMapping> getHandlerMappings(Object bean) {
                try {
                    Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");
                    field.setAccessible(true);
                    return (List<RequestMappingInfoHandlerMapping>) field.get(bean);
                } catch (IllegalArgumentException | IllegalAccessException e) {
                    throw new IllegalStateException(e);
                }
            }
        };
    }