springfox: Can't test the configuration 404 not found
I can’t test the configuration for the Swagger API in Spring Boot Application using http://localhost:8080/forest/v2/api-docs
It is showing 404 not found
Also, http://localhost:8080/forest/swagger-ui.html
is showing 404 not found along with a message
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:
Springfox 2.7.0 Swagger core 1.5.13
pom.xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
SwaggerConf.java
@EnableSwagger2
public class SwaggerConf {
@Bean
public Docket newsApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("greetings")
.apiInfo(apiInfo())
.select()
.paths(regex("/greeting.*"))
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Spring REST Sample with Swagger")
.description("Spring REST Sample with Swagger")
.termsOfServiceUrl("http://www-03.ibm.com/software/sla/sladb.nsf/sla/bm?Open")
.license("Apache License Version 2.0")
.licenseUrl("https://github.com/IBM-Bluemix/news-aggregator/blob/master/LICENSE")
.version("2.0")
.build();
}
}
Web.xml
<servlet>
<servlet-name>servletForest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextAttForest</param-name>
<param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>servletForest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 79 (24 by maintainers)
We too are experiencing the same error. Any guidance would be fantastic. Thanks!
Hi,
I faced the same problem, I could see the /v2/api-docs but not the swagger-ui.html. I fixed it adding this to my WebSecurityConfigurerAdapter class
Kind Regards Jose
Had the same issue and resolved it by following the spring security advice above, but not only for api-docs and swagger-ui.html, but also for swagger-resources and webjars.
Example:
I see those maven dependencies under my project which got added by default by keeping those two dependencies on the pom file.
<dependency> </dependency> <dependency> </dependency>On Tue, Jul 4, 2017 at 12:18 PM, Dilip Krishnan notifications@github.com wrote:
– Debapriya Patra debapriya.patra@gmail.com 9741500237
Fair enough. It is just a few changes to springfox.js, so that is logs errors to console.log, stops keeping poping-up, cancel works…
Hi friends i solve this problem with @Configuration in my configuration class. I hope that this help you. https://github.com/luansousa26/java8-default-crud-application
with the @configuration
Without configuration
I too have the same issue. My app is in Scala. The code compiles and runs but I can’t hit http://locathost:8080/swagger-ui.html I get a 404. on the other hand http://localhost:8080/v2/api-docs works beautifully!
I have dependencies ( I had to downgrade to 2.6,1 from 2.7.0):
In addition, I am not using Spring Security and have added only this class:
The project is available in github here:
https://github.com/jesimone57/spring_boot_scala_rest_example
Any help is greatly appreciated. I created an open_api.yaml spec for the project (in spec folder), so I wanted to see if I could get the annotations to work. But I can’t after many hours of playing around with it.
I have met the same problem and fixed it by adding
/swagger-ui.html**
to permitAll. The**
is nessary, because swagger will request/swagger-ui.html#/
, and without**
spring security will filter the request.FYI
I had the same problem, and fixed it.
I have an spring boot API project, and want to add swagger-ui as docs. The reason it didn’t work is because I have requests verification, such as “AccessToken” verification.
Exclude
/v2/api-docs
from verification makes the API returns expected JSON. Butswagger-ui.html
still return JS errors.@madhumvgr mentions that visit
swagger-ui.html
redirects toswagger-resources/configuration/ui
. So I exclude/swagger-resources/xx
from verification. And finally, Swagger UI works now.Hope it helps.
Hi guys, I was having the same exact problem as many of you have experienced. In case it should be of any help to anyone here, this is how my entire WebSecurity class looks like. It is written in Groovy and I am using Okta’s JwtVerifier for authorization:
Hi All,
I am also stuck at localhost/swagger-ui.html, I see the same error as mentioned before by dpatra1 on Jun 26. I spent lot of time to integrate swagger to spring mvc application. https://user-images.githubusercontent.com/12764176/27525730-16a33b82-59f5-11e7-9d47-3d76d1ad47b0.png In browser console I see 404 resource not found error. Same for other urls like localhost/v2/api-docs and swagger-resources. My code changes are as below: springfox-swagger2 – <version>2.6.0</version> Same error with springfox-swagger2 version 2.7.0 also.
applicationContext.xml
securityconfig
Any help reference docs appreciated…
After some tests, in my case I didn’t have to touch the Spring Security configuration, but rather the class filtering the requests (
... extends OncePerRequestFilter
), in particular the methoddoFilterInternal()
, where a redirection to the webapp root was happening if the URL didn’t start with/api
and wasn’t a filename.@inad9300 Sorry about that, you are correct! I lost the previous method calls when copy/pasting the example code. I’ve updated the example in my comment.