Is it possible to extend WebMvcConfigurationSupport and use WebMvcAutoConfiguration?

后端 未结 4 1538
时光取名叫无心
时光取名叫无心 2020-12-08 08:28

I need to extend the WebMvcConfigurationSupport class too modify two things:

@Configuration
public class WebConfig e         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 09:12

    I managed to customize the RequestMappingHandlerMapping while keeping WebMvcAutoConfiguration using a BeanPostProcessor:

    @Configuration
    public class RequestMappingConfiguration {
        @Bean
        public RequestMappingHandlerMappingPostProcessor requestMappingHandlerMappingPostProcessor() {
            return new RequestMappingHandlerMappingPostProcessor();
        }
    
        public static class RequestMappingHandlerMappingPostProcessor implements BeanPostProcessor {
    
            @Override
            public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
                if (bean instanceof RequestMappingHandlerMapping) {
                    ((RequestMappingHandlerMapping) bean).setUseSuffixPatternMatch(false);
                }
                return bean;
            }
    
            @Override
            public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
                return bean;
            }
        }
    }
    

    I would be happy if Spring Boot provides a better way to handle that... maybe something could be done around PathMatchConfigurer ?

提交回复
热议问题