springfox icon indicating copy to clipboard operation
springfox copied to clipboard

SpringFox bug on Spring Boot 2.6.x

Open gabizinha12 opened this issue 4 years ago • 6 comments

https://gist.github.com/gabizinha12/b7617e261fda2a188db912ced27d833a https://gist.github.com/gabizinha12/1001d25330d0f359cf7e3b38061c14e7 Im using spring version 2.6.4, my springfox version is 3.0.0. I've tried changing path matchers, isnt any other way to workaround this version of springfox to work with Spring Boot 2.6.x? https://github.com/gabizinha12/api-petshop

gabizinha12 avatar Mar 06 '22 03:03 gabizinha12

add bean:

    @Bean
    public BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() {
        return new BeanPostProcessor() {
            @Override
            @SuppressWarnings({"NullableProblems", "unchecked"})
            public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
                if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) {
                    try {
                        Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");
                        if (null != field) {
                            field.setAccessible(true);
                            List<RequestMappingInfoHandlerMapping> mappings = (List<RequestMappingInfoHandlerMapping>) field.get(bean);
                            mappings.removeIf(e -> null != e.getPatternParser());
                        }
                    } catch (IllegalArgumentException | IllegalAccessException e) {
                        throw new IllegalStateException(e);
                    }
                }
                return bean;
            }
        };
    }

and application.yml

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

ciot-plus avatar Mar 14 '22 09:03 ciot-plus

I've tried using the ant path matcher, does it have to be especifically YML? Not .properties?

On Mon, Mar 14, 2022 at 6:18 AM bell0521 @.***> wrote:

add bean: @Bean public BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() { return new BeanPostProcessor() { @Override @SuppressWarnings({"NullableProblems", "unchecked"}) public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) { try { Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings"); if (null != field) { field.setAccessible(true); List<RequestMappingInfoHandlerMapping> mappings = (List<RequestMappingInfoHandlerMapping>) field.get(bean); mappings.removeIf(e -> null != e.getPatternParser()); } } catch (IllegalArgumentException | IllegalAccessException e) { throw new IllegalStateException(e); } } return bean; } }; }

and application.yml spring: mvc: pathmatch: matching-strategy: ant_path_matcher

— Reply to this email directly, view it on GitHub https://github.com/springfox/springfox/issues/3982#issuecomment-1066549843, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQGKNNL3LF4JBIYLMOWKM5DU7377XANCNFSM5QAR55MQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

gabizinha12 avatar Mar 14 '22 11:03 gabizinha12

spring.mvc.pathmatch.matching-strategy=ant_path_matcher

ciot-plus avatar Mar 14 '22 12:03 ciot-plus

I've tried using the ant path matcher, does it have to be especifically YML? Not .properties? On Mon, Mar 14, 2022 at 6:18 AM bell0521 @.> wrote: add bean: @bean public BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() { return new BeanPostProcessor() { @OverRide @SuppressWarnings({"NullableProblems", "unchecked"}) public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) { try { Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings"); if (null != field) { field.setAccessible(true); List<RequestMappingInfoHandlerMapping> mappings = (List<RequestMappingInfoHandlerMapping>) field.get(bean); mappings.removeIf(e -> null != e.getPatternParser()); } } catch (IllegalArgumentException | IllegalAccessException e) { throw new IllegalStateException(e); } } return bean; } }; } and application.yml spring: mvc: pathmatch: matching-strategy: ant_path_matcher — Reply to this email directly, view it on GitHub <#3982 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQGKNNL3LF4JBIYLMOWKM5DU7377XANCNFSM5QAR55MQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you authored the thread.Message ID: @.>

spring mvc pathmatch matching-strategy: ant_path_matcher

TyinOne avatar Mar 28 '22 06:03 TyinOne

the issue seems to be that if you're using spring actuator, setting the matching strategy won't help.

sdomi003 avatar May 02 '22 19:05 sdomi003

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 13 '22 01:08 stale[bot]

This issue has been automatically closed because it has not had recent activity. Please re-open a new issue if this is still an issue.

stale[bot] avatar Sep 22 '22 03:09 stale[bot]