Unable to infer base url… springfox-swagger2 version 2.9.2

前端 未结 2 456
野性不改
野性不改 2021-01-16 15:11

Version of springfox-swagger that I am using

What kind of issue is this? Project structure: SwaggerConfig is in automate.api.config.swagger.Swagger

2条回答
  •  Happy的楠姐
    2021-01-16 16:01

    Now, I managed to solve my issue. One of the issues was the pathMApping.

    I needed to change my configuration to explicitly to "/", like here

    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import springfox.documentation.builders.PathSelectors;
    import springfox.documentation.builders.RequestHandlerSelectors;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    import springfox.documentation.swagger2.annotations.EnableSwagger2;
    
    @Configuration
    @EnableSwagger2
    public class SwaggerConfiguration {
      @Bean
      public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any())
            .build()
            .pathMapping("/");
      }
    }
    

    Other issue was I used ResponseBodyAdvice

    import io.falcon.automate.api.web.views.BaseView;
    import io.falcon.automate.api.web.views.ErrorView;
    import org.springframework.core.MethodParameter;
    import org.springframework.http.MediaType;
    import org.springframework.http.converter.HttpMessageConverter;
    import org.springframework.http.server.ServerHttpRequest;
    import org.springframework.http.server.ServerHttpResponse;
    import org.springframework.web.bind.annotation.ControllerAdvice;
    import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
    
    
    @ControllerAdvice
    public class ResponseAdvice implements ResponseBodyAdvice {
    
        @Override
        public boolean supports(MethodParameter returnType, Class> converterType) {
            return true;
        }
    
        /**
         * Wraps all responses in base view class
         * @param body
         * @param returnType
         * @param selectedContentType
         * @param selectedConverterType
         * @param request
         * @param response
         * @return
         */
        @Override
        public Object beforeBodyWrite(
                Object body,
                MethodParameter returnType,
                MediaType selectedContentType,
                Class> selectedConverterType,
                ServerHttpRequest request,
                ServerHttpResponse response
        ) {
            if (body instanceof ErrorView) {
                return body;
            }
            return new BaseView(body);
        }
    }
    
    
    
    

    If I commented out my response wrapper class, everything works like a charm.....

    The only issue, that I need my response wrapper. :/

    提交回复
    热议问题