Reputation: 41
I configured swagger UI but I couldn't see the screen, I'm getting a 404 error, can anyone tell me how to solve the problems?
maven dependency's
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
SwaggerConfig file
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket apiDocket() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any()).build();
}
}
Upvotes: 1
Views: 2763
Reputation: 86
you have to add only this dependency,and Remove @EnableSwagger2
,after check it out url ../swagger-ui/index.html
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
Upvotes: 0
Reputation: 109
swagger version 3.0.0 has changed the url to /context-path/swagger-ui/ or /context-path/swagger-ui/index.html
This documented on the swagger-ui github https://springfox.github.io/springfox/docs/snapshot/#migrating-from-existing-2-x-version
Upvotes: 0
Reputation: 1088
try this config
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
public static final String SWAGGER_SCAN_BASE_PACKAGE = "notificationservice.web";
@Bean
public Docket api() {
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE))
.paths(PathSelectors.any())
.build().apiInfo(apiInfo())
.securitySchemes(Arrays.asList(apiKey()))
.securityContexts(Collections.singletonList(securityContext()));
return docket;
}
public ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Notification Service API")
.description("Notification Service API Documentation")
.license("Aapche 2.0")
.licenseUrl("https://github.com/dvsigh9/licence")
.build();
}
private SecurityContext securityContext() {
return SecurityContext.builder().securityReferences(defaultAuth()).forPaths(PathSelectors.regex("/.*")).build();
}
private List<SecurityReference> defaultAuth() {
final AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
final AuthorizationScope[] authorizationScopes = new AuthorizationScope[]{authorizationScope};
return Collections.singletonList(new SecurityReference("Bearer Token", authorizationScopes));
}
private ApiKey apiKey() {
return new ApiKey("Bearer Token", "Authorization", "header");
}
}
Upvotes: 2