简体   繁体   English

不为Spring Boot应用程序生成的Swagger文档

[英]Swagger Docs not generating for Spring Boot app

I am pretty new to spring boot but for some reason my swagger ui is not allowing me to accees the API. 对于Spring Boot,我还很陌生,但是由于某种原因,我的招摇的ui不允许我使用该API。 I tried to follow a couple tutorials but no luck on being able to see the API's. 我尝试按照一些教程学习,但是对能够看到API并不满意。 Below is the screenshot that I get when loading (I tried a couple other URLs as well) and some relevant code. 以下是加载时获得的屏幕截图(我也尝试了其他两个URL)和一些相关代码。

在此处输入图片说明

Spring Boot Application Spring Boot应用程序

@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", "myemail@gmail.com"))
            .version("1.0")
            .build();
    }
}

Greeting Controller 问候控制器

@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 Gradle.build

 buildscript { ext { springBootVersion = '1.5.8.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } 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 { mavenCentral() } jar { baseName = 'gs-rest-service' version = '0.1.0' } ext { springCloudVersion = 'Dalston.SR4' } dependencies { compile('org.springframework.cloud:spring-cloud-starter-hystrix') compile("org.springframework.boot:spring-boot-starter-web") compile 'io.springfox:springfox-swagger-ui:2.7.0' compile "io.springfox:springfox-swagger2:2.7.0" testCompile('org.springframework.boot:spring-boot-starter-test') } dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" } } 

@EnableSwagger2添加到您的配置类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM