这是我使用的配置和依赖项:
this._communication.changeSubject(true);
这是配置:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
当我使用此路径时:http://localhost:8090/v2/api-docs给了我json。 但是当我想使用http://localhost:8090/swagger-ui.html时不起作用。 感谢您对我的帮助。
答案 0 :(得分:0)
尝试扩展WebMvcConfigurationSupport,如下所示,并覆盖添加ResourceHandlers并为您工作。
@Configuration
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurationSupport {
public static final Contact DEFAULT_CONTACT = new Contact("Nagaraja", "", "email-id");
private static final Set<String> DEFAULT_PRODUCES_AND_CONSUMES = new HashSet<>(
Arrays.asList("application/json"));
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(metaData()).produces(DEFAULT_PRODUCES_AND_CONSUMES)
.consumes(DEFAULT_PRODUCES_AND_CONSUMES).select()
.apis(RequestHandlerSelectors.basePackage("controller-package")).paths(PathSelectors.any())
.build();
}
private ApiInfo metaData() {
return new ApiInfoBuilder().title("REST API")
.description("Write description").version("1.0.0")
.license("Apache License Version 2.0").licenseUrl("https://www.apache.org/licenses/LICENSE-2.0")
.contact(DEFAULT_CONTACT).build();
}
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
Maven依赖项:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
<scope>compile</scope>
</dependency>