我的不是application.properties 是 application.yml
时间: 2023-07-08 19:36:53 浏览: 46
好的,如果你使用的是application.yml配置文件,那么你可以将上面提到的配置转换为yml格式:
```yaml
# Swagger UI主题
knife4j:
swagger-ui:
path: /doc.html
title: Swagger2接口文档
description: Swagger2接口文档
version: 1.0
contact:
name: 联系人姓名
email: 联系人邮箱
url: 联系人网址
license:
name: 许可证名称
url: 许可证网址
enable: true
# 配置主题
theme: flattop
```
同时,在你的配置类中,你也需要将@Bean注解替换为@ConfigurationProperties注解:
```java
@Configuration
@EnableSwagger2
@ConfigurationProperties(prefix = "knife4j.swagger-ui")
public class Swagger2Config {
private String path;
private String title;
private String description;
private String version;
private Contact contact;
private License license;
private Boolean enable;
private String theme;
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title(title)
.description(description)
.termsOfServiceUrl(path)
.version(version)
.contact(contact)
.license(license)
.build();
}
// 省略getter和setter方法
}
```
这样,你就可以在application.yml中配置Swagger UI的主题了。