• 周四. 10 月 3rd, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

Spring boot integrates swagger

King Wang

1 月 3, 2022

Extremely simple SpringBoot Integrate Swagger

reference

Learn from open source projects com.spring4all.swagger-spring-boot-starter.

rely on

<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>1.9.0.RELEASE</version>
</dependency>

Use steps

Add in startup class @EnableSwagger2Doc annotation

@EnableSwagger2Doc
@SpringBootApplication
public class Bootstrap {

public static void main(String[] args) {

SpringApplication.run(Bootstrap.class, args);
}
}

By default, all current Spring MVC Loaded request mapping document .

To write Controller

@RestController("hello")
public class HelloController {

@ApiOperation(value = "Hello World", authorizations = {
@Authorization(value = "Authorization")})
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String hello(){

}
}

visit swagger-ui Interface

http://localhost:8080/swagger-ui.html/

Reference material

  • https://github.com/SpringForAll/spring-boot-starter-swagger

发表回复