use*_*693 31 java spring swagger swagger-ui spring-boot
我已经将swagger插入我的春季启动应用程序.Spring启动允许您拥有每个环境的属性文件.有没有办法禁用生产环境的招摇?
lub*_*nac 25
将您的swagger配置放入单独的配置类中,并使用@Profile
注释 - > 对其进行注释,以便仅在某些配置文件中将其扫描到Spring上下文中.
例:
@Configuration
@EnableSwagger2
@Profile("dev")
public class SwaggerConfig {
// your swagger configuration
}
Run Code Online (Sandbox Code Playgroud)
您可以通过命令行定义Spring Boot应用程序运行的--spring.profiles.active=dev
配置文件:或通过配置文件:spring.profiles.active=dev
.
阅读Spring Boot文档的这一部分以获取更多信息 @Profile
Per*_*vez 20
如果您正在处理多个环境,那么您也可以使用@Profile作为数组
@Configuration
@EnableSwagger2
@Profile({"dev","qa"})
public class SwaggerConfig {
// your swagger configuration
}
Run Code Online (Sandbox Code Playgroud)
小智 10
使用swagger 3.0.0版本,您可以springfox.documentation.enabled=false
在相应的环境配置application.properties
文件中添加。例如,我已将其添加到application-prod.properties
生产中以禁用(运行应用程序时,您必须使用 VM args 指定配置文件,例如-Dspring.profiles.active=prod
)
这是我的配置类:
@Configuration
@Profile("swagger")
@EnableSwagger2
public class SwaggerConfig {
@Value("${info.build.version}")
private String buildVersion;
@Bean
public Docket documentation() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(regex("/rest/.*"))
.build()
.pathMapping("/")
.apiInfo(metadata());
}
private ApiInfo metadata() {
return new ApiInfoBuilder()
.title("API documentation of our App")
.description("Use this documentation as a reference how to interact with app's API")
.version(buildVersion)
.contact(new Contact("Dev-Team", "https://dev-website", "dev@mailbox"))
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
无论我在哪里需要 Swagger,我都会将配置文件添加swagger
到环境变量中 SPRING_PROFILES_ACTIVE
归档时间: |
|
查看次数: |
29391 次 |
最近记录: |