私はSwaggerにはかなり新しく、私はSpring Bootを使用して構築した非常に簡単なWebサービスを文書化し始めました。Spring BootでSwaggerを設定中に予期せぬ結果を得る
私が闊歩を設定した後、問題は、私はlocalhostを入力すると、ブラウザでは、次のとおりです。8080 /威張っ-ui.htmlを私は「ベースURLを推測することができませんと言ういくつかの奇妙なポップアップメッセージで、この次の画面を取得します。この動的サーブレット登録を使用する場合や、APIがAPIゲートウェイの背後にある場合は共通です。
私はそれが繰り返し質問されるかもしれないことは知っていますが、私はすべてのこれらの答えでこれを解決することができませんでした。その後、私は間違っていなかったスクリーンショットと完全なコードを投稿しました。私が間違っていたら私に理解させてください。
コード
SwaggerConfig.java
package com.test.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import static springfox.documentation.builders.PathSelectors.regex;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.paths(regex("/greet.*"))
.build();
}
}
TestApplication.java
package com.test.config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(basePackages="com.test.controllers")
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
TestController.java
両方SwaggerConfig.javaとTestApplication.javaがcom.test.configとTestController.javaすなわち、同じパッケージに属する上記のコードで
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/greet")
public class TestController {
@RequestMapping
public String getGreeting() {
return "Hello There";
}
}
は
com.test.controllersに属し
これは私がしたすべてのコードであるとのpom.xmlに私は2つの次の依存
をしました<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
<scope>compile</scope>
</dependency>
にアクセスします。場合によっては、ブラウザの拡張機能をオンにすると、これらのものがポップアップすることがあります。シークレットウィンドウやその他のブラウザで試してください – Barath
Mozillaのような一部のブラウザでは、アラート画面は表示されませんが、ドキュメントはまったく表示されません。 TestControllerでは、getGreeting()メソッドのためにドキュメントが正しく表示されるはずですか? –
@Barath本当に、あなたはドキュメントを見ることができますか? –