LoginSignup
4
5

More than 3 years have passed since last update.

Spring Boot + Springfox springfox-boot-starter 3.0.0つかう

Posted at

https://github.com/springfox/springfox をつかう。

build.gradle
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-configを作る必要がない。

swagger333.jpg

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5