我给项目A配置了Knife4j,我就按照A的配置方式给项目B配置。结果发现,B访问时总是出现下面的问题,然后我就重新搞了一种新的方法
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Aug 29 15:00:59 CST 2024
There was an unexpected error (type=Not Found, status=404).
1. 引入依赖
<!--swagger-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
2. 配置
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.iflytek.warning.controller(这里要换成自己的)"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("苏州机动车 API文档")
.description("苏州机动车")
.version("1.0.0")
.contact(new Contact("联系人", "https://ruoyi.vip/", "邮箱"))
.build();
}
}
3. 访问Knife4j 注意:访问路径千万不能写错
http://localhost:8066/warning-platform/doc.html
可以啦