美文网首页
Failed to start bean ‘documentat

Failed to start bean ‘documentat

作者: 零宽度接合 | 来源:发表于2022-12-08 17:46 被阅读0次

Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.NullPointerEx

新增配置类

import org.springframework.beans.BeansException;

import org.springframework.beans.factory.config.BeanPostProcessor;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import org.springframework.util.ReflectionUtils;

import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;

import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider;

import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;

import java.lang.reflect.Field;

import java.util.List;

import java.util.stream.Collectors;

@Configuration

public class BeanPostProcessorConfig {

@Bean

    public static BeanPostProcessorspringfoxHandlerProviderBeanPostProcessor() {

return new BeanPostProcessor() {

@Override

            public ObjectpostProcessAfterInitialization(Object bean, String beanName)throws BeansException {

if (beaninstanceof WebMvcRequestHandlerProvider || beaninstanceof WebFluxRequestHandlerProvider) {

customizeSpringfoxHandlerMappings(getHandlerMappings(bean));

                }

return bean;

            }

private void customizeSpringfoxHandlerMappings(List mappings) {

List copy = mappings.stream()

.filter(mapping -> mapping.getPatternParser() ==null)

.collect(Collectors.toList());

                mappings.clear();

                mappings.addAll(copy);

            }

@SuppressWarnings("unchecked")

private ListgetHandlerMappings(Object bean) {

try {

Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");

                    field.setAccessible(true);

                    return (List) field.get(bean);

                }catch (IllegalArgumentException | IllegalAccessException e) {

throw new IllegalStateException(e);

                }

}

};

    }

}

相关文章

网友评论

      本文标题:Failed to start bean ‘documentat

      本文链接:https://www.haomeiwen.com/subject/iseafdtx.html