这是我的代码:我从 application.properties 文件 SwaggerConfig.java 获取所有值
@Configuration
@EnableSwagger2
@Profile("!prod")
@PropertySource(value = { "classpath:application.properties" })
public class SwaggerConfig {
@Value("${swagger.api.title}")
private String title;
@Value("${swagger.api.description}")
private String description;
@Value("${swagger.api.termsOfServiceUrl}")
private String termsOfServiceUrl;
@Value("${swagger.api.version}")
private String version;
@Value("${swagger.api.controller.basepackage}")
private String basePackage;
@Bean
public Docket postMatchApi() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.basePackage(basePackage))
.paths(PathSelectors.ant("/**")).build().apiInfo(metaData());
}
private ApiInfo metaData() {
return new ApiInfoBuilder().title(title).description(description).termsOfServiceUrl(termsOfServiceUrl)
.version(version).build();
}
Run Code Online (Sandbox Code Playgroud)
这是我的 springboot 初始化程序:
@SpringBootApplication
@ComponentScan(basePackages = { "com.example.demo" })
@ComponentScan(basePackageClasses = {AppInitializer.class, SwaggerConfig.class})
@EnableAsync
@EnableRetry
public class AppInitializer{
public static void main(String[] args) { …Run Code Online (Sandbox Code Playgroud)