swagger2显示错误解决:Could not render e, see the console.
同时可以根据environment去处配置要给那些开发环境设置swagger文档,底层会通过扫描配置文件中的active来判断当前的开发环境。环境符合则flag返回true,false则会显示不可用。出现这种情况就是swagger的配置类出了问题,在.enable()中传入了false。active: pro#dev(开发)#pro(生产)
·
出现这种情况就是swagger的配置类出了问题,在.enable()中传入了false。
同时可以根据environment去处配置要给那些开发环境设置swagger文档,底层会通过扫描配置文件中的active来判断当前的开发环境。环境符合则flag返回true,false则会显示不可用。
spring: profiles: active: pro #dev(开发) #pro(生产)
具体配置如下:
@Configuration
@EnableSwagger2
//@EnableWebMvc
public class SwaggerConfig implements WebMvcConfigurer {
@Bean
public Docket docket(Environment environment) {
Profiles profiles = Profiles.of("pro", "test"); //设置要显示的swagger环境
boolean flag = environment.acceptsProfiles(profiles); //生产、测试环境返回true
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.enable(flag)
.select()
.apis(RequestHandlerSelectors.basePackage("com.dgut.www.admin"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("微信小程序")
.description("简历模块接口")
.version("1.0.0")
// 作者信息
.contact(new Contact("dgut", "", ""))
.build();
}
}
更多推荐
所有评论(0)