Spring套件版本
Springboot版本:2.0.6.RELEASE
Spring版本:5.0.10.RELEASE
swagger2组件依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
<scope>compile</scope>
</dependency>
ui组件
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-ui</artifactId>
<version>3.0.3</version>
</dependency>
配置
@Configuration
@EnableConfigurationProperties(value = {SwaggerProperties.class})
@EnableSwagger2
public class SwaggerConfig {
@Autowired
private SwaggerProperties swaggerProperties;
@Bean
public ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title(swaggerProperties.getTitle())
.description(swaggerProperties.getDescription())
.version(swaggerProperties.getApiVersion())
.build();
}
@Bean
public Docket commonApiInner() {
return new Docket(DocumentationType.SWAGGER_2)
// .host(ObjectUtils.isEmpty(swaggerProperties.getHostname())?"http://localhost:" + serverProperties.getPort():swaggerProperties.getHostname())
.groupName("流程引擎")
.apiInfo(apiInfo()).select()
.build();
}
}
@ConfigurationProperties(prefix = "swagger.config")
@Setter
@Getter
@Configuration
public class SwaggerProperties {
private String hostname;
private String title;
private String description;
private Integer port;
private String apiVersion = "/api/v1";
}
效果:

image.png