使用knife4j报错Parameter 0 of constructor in springfox.documentation.swagger.schema.ApiModelPropertyPr..
·
详细报错:
今天在使用knife4j整合swagger2聚合微服务文档时报错(其中一个服务):
Description: Parameter 0 of constructor in springfox.documentation.swagger.schema.ApiModelPropertyPropertyBuilder required a bean of type 'springfox.documentation.spring.web.DescriptionResolver' that could not be found. Action: Consider defining a bean of type 'springfox.documentation.spring.web.DescriptionResolver' in your configuration.
Description:
Parameter 0 of constructor in springfox.documentation.swagger.schema.ApiModelPropertyPropertyBuilder required a bean of type 'springfox.documentation.spring.web.DescriptionResolver' that could not be found.
Action: Consider defining a bean of type 'springfox.documentation.spring.web.DescriptionResolver' in your configuration.
问题代码:
依赖:
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-micro-spring-boot-starter</artifactId>
<version>2.0.8</version>
</dependency>
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
</dependency>
knife4j配置:
@Configuration
@EnableSwagger2
@EnableKnife4j
public class Swagger2Config {
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.et.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("认证授权")
.description("认证授权API")
.contact("chen")
.version("1.0")
.build();
}
}
原因分析(不太准确):
这个错误表明在Spring Boot启动时,无法找到类型为 springfox.documentation.spring.web.DescriptionResolver 的bean。通常情况下,这种错误可能是由于缺少必要的依赖或配置导致的。网上也有另一种说法说springboot版本太高导致,或者依赖冲突导致等,
可以尝试添加依赖,
解决办法:
添加依赖:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
修改代码:
将ApiInfoBuilder的.contact()方法删除
如以下代码所示:
/**
* Swagger API相关配置
*/
@Configuration
@EnableSwagger2
@EnableKnife4j
public class Swagger2Config {
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.et.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("认证授权")
.description("认证授权API")
.version("1.0")
.build();
}
}
我这里完美解决希望能帮到大家💖
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)