This is how I solved my problem. Here is my detailed code, if someone want to look.
https://github.com/xbox2204/SpringBoot-JPA-Swagger
Now, I used 3.0.0-SNAPSHOT and a latest spring-boot starter project I created from here:
https://start.spring.io/
- My pom.xml, I added following dependencies:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
- In my application.properties, I added following:
spring.resources.add-mappings=true
- In my SpringBoot Main/Runner class, I added these annotations
@EnableWebMvc
@EnableSwagger2
@SpringBootApplication
- My Docket returning function looked like this
@Bean
public Docket productApi() {
Contact contact =new Contact(
"Vineet Mishra",
"https://github.com/xbox2204",
"[email protected]"
);
ApiInfo apiInfo= new ApiInfoBuilder().title("VINEET SPRING-BOOT API")
.description("Spring-Boot for all")
.termsOfServiceUrl("jUST CHILL!!!")
.contact(contact)
.licenseUrl("[email protected]").version("1.0").build();
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo)
.select()
.apis(RequestHandlerSelectors.any())
.build();
}
- Finally, I accessed my swagger-ui from
http://localhost:8080/swagger-ui/index.html#
Image of final result