使用Spring Boot + Springfox springfox-boot-starter 3.0.0
使用的是https://github.com/springfox/springfox。
plugins {
id 'org.springframework.boot' version '2.3.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
// https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter
implementation 'io.springfox:springfox-boot-starter:3.0.0'
}
test {
useJUnitPlatform()
}
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@SpringBootApplication
public class MainApp {
@GetMapping("/hoge")
public String hoge() {
return "hoge";
}
public static void main(String[] args) {
SpringApplication.run(MainApp.class, args);
}
}
只需一个选项的汉语表达:
当使用这个启动命令后,访问 http://localhost:8080/swagger-ui/index.html,将会显示以下页面。与2.0之前的版本不同,由于有了auto-config,所以不需要创建用于swagger的java配置文件。