I'm pretty much new to Swagger and I started Documenting very simple my web service that I've build using Spring Boot.
The problem is, After I configure swagger, in the browser when I type localhost:8080/swagger-ui.html I get this following screen with some weird popup message that says "Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway".
I do know it may seems repeated question, but I couldn't resolve this at all with all those answers given. Following, I've posted the screenshot and complete code where I didn't what went wrong. Please make me understand If I went wrong.
Code
SwaggerConfig.java
package com.test.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import static springfox.documentation.builders.PathSelectors.regex;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.paths(regex("/greet.*"))
.build();
}
}
TestApplication.java
package com.test.config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(basePackages="com.test.controllers")
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
TestController.java
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/greet")
public class TestController {
@RequestMapping
public String getGreeting() {
return "Hello There";
}
}
In the above code both SwaggerConfig.java and TestApplication.java belongs to same package i.e com.test.config and TestController.java belongs to com.test.controllers
This is all the code I've and in the pom.xml I've two following dependencies
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
<scope>compile</scope>
</dependency>