Implementation of Swagger.io und Postman to Springboot
Hello Hive and Java Developers and the rest,
as I wrote in my last post, I am setting up a java springboot server, which, when it is finished somewhere far in the future, shall contain a new game "Hamurabi", which will be connected to hive.
Here, in this post, I show, how I have set up Swagger and Postman:
This documentation is based on: @achimmertens/hamurabi-spring-boot-server
Swagger
I have added the following to pom.xml:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
To avoid the error message "Failed to start bean 'documentationPluginsBootstrapper';"
I have added into application.properties:
#======================================
# Swagger
#======================================
spring.mvc.pathmatch.matching-strategy=ant-path-matcher
I have created the config file swagger.config in the configuration package:
Here is its content:
package org.chary.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
public static final Contact DEFAULT_CONTACT = new Contact(
"Achim Mertens", "http://peakd.com/@achimmertens", "achim_mertens@gmx.de");
private static final Set<String> DEFAULT_PRODUCES_AND_CONSUMES =
new HashSet<String>(Arrays.asList("application/json","application/xml"));
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(SwaggerConfig.apiInfo())
.produces(DEFAULT_PRODUCES_AND_CONSUMES)
.consumes(DEFAULT_PRODUCES_AND_CONSUMES);
}
private static ApiInfo apiInfo() {
return new ApiInfoBuilder().title("Swagger API")
.description("Swagger API reference for developers")
.version("2.0")
.contact(DEFAULT_CONTACT)
.termsOfServiceUrl("http://peakd.com/@achimmertens")
.licenseUrl("https://www.apache.org/licenses/LICENSE-2.0").build();
}
}
Now, after starting the server, I can see that swagger works:
Postman
I go to https://www.postman.com/downloads/ and download postman.
After Installing the app I start it an click on New/http Request (you don't need to register):
Now, I check, if I get my wished response:
Yes it works :-)))
The next thing is to set up the server to receive data. So stay tuned.
Regards, Achim
Leave Implementation of Swagger.io und Postman to Springboot to:
Read more #java posts
Best Posts From Achim Mertens
We have not curated any of achimmertens's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Achim Mertens
- Wenn der Arbeitgeber keine KI zulässt: Wie man ein Mail-KI-Chat-Gateway baut
- My Diary For Week 31
- Wie man einen Email-Auswerte-Workflow mit N8N erstellt
- My Diary For Week 30
- My Diary For Week 29
- My Diary For Week 28
- My Diary For Week 27
- My Diary For Week 26
- Mein IAM+PAM System auf dem Raspberry Pi
- My Diary For Week 25