我对春季靴子很新,但出于某种原因,我的招摇ui不允许我加入API。我尝试了几个教程,但没有运气能够看到API。下面是我在加载时获得的屏幕截图(我还尝试了其他一些URL)和一些相关代码。
Spring Boot Application
@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();
}
}
问候控制器
@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 {
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}"
}
}
答案 0 :(得分:1)
将@EnableSwagger2
添加到您的配置类。