New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swagger support for Spring Boot 2 / Spring 5? #2155
Comments
@springframeworkguru spring boot 2 and spring fx 5 aren't really supported as of now. Trying to get the next release (2.8.0) in before starting to work on it. Let me look at your repo and see what the issue might be. |
Thanks @dilipkrish! Appreciate the help. I just committed my changes on this branch. |
@dilipkrish - Got it working. Something broke the config in Spring 5 / Spring Boot. I had to add config for resource handlers. For others hitting this issue: Note: @EnableSwagger2
@Configuration
public class SwaggerConfig extends WebMvcConfigurationSupport {
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors
.basePackage("guru.springframework"))
.paths(regex("/api/v1/*"))
.build();
}
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}``` |
Oh cool! So in your experience everything related to traditional mvc works as expected? |
I think so. Seems only Swagger UI was broken. With the above config, Swagger UI is looking good. I'm developing a section on Swagger for my Spring 5 course. So, I'll be getting into the various config options over the next few days. Fingers crossed! |
Thats encouraging! So the new functional endpoints are working as well? I'll update this post when 2.8.0 is released (hoping soon enough!) |
Have not tested functional endpoints - not yet! |
For a moment there I was excited! sigh! |
In our project Swagger 2.7.0 works correctly with Spring Boot 2.0.0.M3 without adding resource handlers. |
I saw that yesterday - I ran through it again, I wasn't able to recreate it. I reviewed the code changes & could not spot the delta. No idea what I was doing to cause it... I was working with M7. Going to close this issue. Thanks! |
Swagger2 does not working with Spring Boot 2 when we add embedded reactive connectors(netty). Because Swagger has dependency from Spring web MVC, and if you exclude tomcat, swagger will fail. Just tested with Spring Boot 2. |
@armdev thanks for letting us know! |
Hi @springframeworkguru , i'm running Spring Boot 2, and trying to make run Swagger 2 on top of it. `2018-03-22 07:05:12.280 WARN 1928 --- [nio-8080-exec-2] o.s.web.servlet.PageNotFound : No mapping found for HTTP request with URI [/v2/api-docs/swagger-ui.html] in DispatcherServlet with name 'dispatcherServlet' To make short : http://localhost:8080/v2/api-docs -> OK, looks perfect ! I've used the code provided by @springframework guru in this ticket. Any idea what i should to to make it up and running please ?...it's so frustrating not to see the html ;-p Thanks in advance for any help. I'm on the 2.8.0 |
I was initially using the following tutorial (bfefore to switch on this issue) : https://springframework.guru/spring-boot-restful-api-documentation-with-swagger-2/ |
I pushed project with Spring boot 2 and swagger https://github.com/armdev/springboot2-swagger , but application configured as a "servlet", not a "reactive", |
Thanks a lot @armdev , i'm taking a look at it, i'll let you know as soon as it works 👍 |
I've just run your code locally without any problem. just
and swagger-ui is up an running. Ill use htis as a tutorial now. Thanks a lot @armdev for great help. |
@armdev : your code allowed me to make swagger-ui work with only few lines of code on the main app 👍 💯 |
Hi @springframeworkguru/ @armdev, I am running a Spring boot 2.2.0 with swagger version 2.9.2 and in swagger configuration file if I am using @configuration and @EnableSwagger2, getting the following error: APPLICATION FAILED TO START Description: An attempt was made to call a method that does not exist. The attempt was made from the following location:
The following method did not exist:
The method's class, org.springframework.plugin.core.PluginRegistry, is available from the following locations:
It was loaded from the following location:
Action: Correct the classpath of your application so that it contains a single, compatible version of org.springframework.plugin.core.PluginRegistry Any help would be appreciated. |
@AdityaJaiswal7 could you please provide a more detailed answer for someone who is new to Java? :) |
I am using Spring Boot 2.1.5 and swagger 2.9.2 now http://localhost:8080/v2/api-docs is working fine and I am able to get json for my api documentation, where as http://localhost:8080/swagger-ui.html gives me whitelabel page. I added
for WebMvcConfigurationSupport. Any suggestions please |
I got it working with the following setup: #pom.xml
#SpringFoxConfig.java
#URL: I know it's just a snapshot version at the moment, but for my purpose it's totally fine for now. |
Hi, I am using Spring below version <java.version>1.8</java.version> I have added swagger dependency io.springfox springfox-swagger-ui 2.7.0 io.springfox springfox-swagger2 2.7.0Config class: package com.merck.midas.config; import org.springframework.context.annotation.Bean; import springfox.documentation.builders.PathSelectors; @EnableWebMvc
} In API class added @EnableSwagger2 @ApiOperation(value="View filter", notes = "viewFilter") .. some business logic When i launch my application i get stuck with Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually: I tried with http://localhost:8080/v2/api-docs- got 404 error. Any help would be appreciated. Have any one tried using spring 5.X version instead of spring boot. Is swagger support spring 5.2.2 Thanks in advance. |
I'm getting a 404 on the Swagger UI url with a Spring Boot 2 (M7) project. Is there any config I need to do for Spring Boot 2 / Spring 5 (Spring MVC. not using Reactive).
Here's my project: https://github.com/springframeworkguru/spring5-mvc-rest/tree/vendor-api
You'll see its a pretty simple project (no Spring Sec).
I added deps for the 2.7.0 version and the following config:
The JSON endpoint works fine. Only the Swagger UI endpoint is returning a 404.
Thanks!
The text was updated successfully, but these errors were encountered: