@configuration@enableswagger2公共类SwaggerConfig {
//Bean - Docket
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2);
}
在WebSecurityConfiguration中添加以下行
.antMatchers("/swagger**", "/webjars/**", "/swagger-resources/**", "/v2/api**").permitAll() // permit all swagger url
如果您想在Springfox中添加下面的JWT身份验证
private ApiKey apiKey() {
return new ApiKey("JWT", "Authorization", "header");
}
private SecurityContext securityContext() {
return SecurityContext.builder().securityReferences(defaultAuth()).build();
}
private List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
return Collections.singletonList(new SecurityReference("JWT", authorizationScopes));
}
private ApiInfo apiInfo() {
return new ApiInfo(
"Title",
"Description",
"1.0",
"Terms of service",
new Contact("name", "URL", "name@email.com"),
"License of API",
"API license URL",
Collections.emptyList());
}