Ich bin ziemlich neu in Spring Boot aber aus irgendeinem Grund erlaubt mir mein Swagger nicht, die API zu bekommen. Ich habe versucht, ein paar Tutorials zu folgen, aber kein Glück, dass ich die APIs sehen konnte. Unten ist der Screenshot, den ich beim Laden bekomme (ich habe auch ein paar andere URLs ausprobiert) und etwas relevanten Code.Swagger Docs generiert nicht für Spring Boot App
Frühlings-Boot-Anwendung
@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();
}
}
Gruß-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
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 }
}
können Sie versuchen, indem Sie @RequestMapping ("api/v1") als @RequestMapping (Wert = "api/v1") und @RequestMapping ("/ Gruß") als @RequestMapping (Wert = "/ Gruß")) –
Versuchen Sie @ EnableSwagger2 zu Ihrer Config-Klasse hinzuzufügen. – Justas
Danke @Justas du warst 100% korrekt. Ich habe das versehentlich vergessen. Vielen Dank – mornindew