0
私は春のブートにはかなり新しいですが、なんらかの理由で私のswagger UIがAPIにアクセスすることができません。私はいくつかのチュートリアルに従おうとしましたが、APIを見ることはできません。以下は、読み込み時に取得するスクリーンショット(他にもいくつかのURLを試しました)と関連するコードです。Swagger DocsがSpringブートアプリケーション用に生成されていない
スプリングブートアプリケーション
@SpringBootApplication(scanBasePackages={"com.starter.controllers"})
public class StarterRestStarterApplication {
public static void main(String[] args) {
SpringApplication.run(StarterRestStarterApplication.class, args);
}
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("A simple starter service")
.description("A simple calculator REST service made with Spring Boot in Java")
.contact(new Contact("my info", "http://myurl.com", "[email protected]"))
.version("1.0")
.build();
}
}
グリーティングコントローラ
@RestController
@RequestMapping("api/v1")
public class GreetingController {
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new GreetingService().greet(name);
}
}
Gradle.build
buildscript {
\t ext {
\t \t springBootVersion = '1.5.8.RELEASE'
\t }
\t repositories {
\t \t mavenCentral()
\t }
\t dependencies {
\t \t classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
\t }
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
group = 'com.starter'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
\t mavenCentral()
}
jar {
baseName = 'gs-rest-service'
version = '0.1.0'
}
ext {
\t springCloudVersion = 'Dalston.SR4'
}
dependencies {
\t compile('org.springframework.cloud:spring-cloud-starter-hystrix')
\t compile("org.springframework.boot:spring-boot-starter-web")
\t compile 'io.springfox:springfox-swagger-ui:2.7.0'
\t compile "io.springfox:springfox-swagger2:2.7.0"
\t testCompile('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
\t imports {
\t \t mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
\t }
}
@RequestMapping(value = "/ greeting")として@RequestMapping( "api/v1")を@RequestMapping(value = "api/v1")と@RequestMapping( "/ greeting" ) –
あなたの設定クラスに@ EnableSwagger2を追加してみてください。 – Justas
ありがとうございました@Justasあなたは100%正しかったです。私はそれを偶然忘れてしまった。 ありがとう – mornindew