spring - Added Springfox Swagger-UI and it's not working, what am I missing? -
following instructions here:
http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api
i added these dependencies project:
compile "io.springfox:springfox-swagger2:2.7.0" compile "io.springfox:springfox-swagger-ui:2.7.0" and configured springfox swagger this:
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 swaggerconfig { @bean public docket api() { return new docket(documentationtype.swagger_2) .select() .apis(requesthandlerselectors.any()) .paths(pathselectors.any()) .build(); } } but swagger ui seems not enabled. tried:
- http://localhost:8080/swagger-ui.html
- http://localhost:8080/api/swagger-ui.html
- http://localhost:8080/v2/api-docs/swagger-ui.html
and is:
whitelabel error page application has no explicit mapping /error, seeing fallback. mon sep 11 09:43:46 bst 2017 there unexpected error (type=method not allowed, status=405). request method 'get' not supported and on logs see:
2017-09-11 09:54:31.020 warn 15688 --- [nio-8080-exec-6] o.s.web.servlet.pagenotfound : request method 'get' not supported 2017-09-11 09:54:31.020 warn 15688 --- [nio-8080-exec-6] .w.s.m.s.defaulthandlerexceptionresolver : resolved exception caused handler execution: org.springframework.web.httprequestmethodnotsupportedexception: request method 'get' not supported http://localhost:8080/swagger-resources returns:
[{"name": "default", "location": "/v2/api-docs", "swaggerversion": "2.0"}] what missing?
i ran issue because had endpoints request mappings had path variables of form: /{var}. turns out issue both , post endpoints i.e. /{var} , post /{var} block swagger-ui. once made paths more specific, got swagger-ui work.
quote https://github.com/springfox/springfox/issues/1672
when spring founds simple path 1 variable swagger cannot intercept urls.
found investigating various ideas in comments.
Comments
Post a Comment