1.最實(shí)用解決方式:將pom里的swagger依賴降到2.9.0即可 過(guò)低無(wú)法啟動(dòng)項(xiàng)目
1.2 Springboot2.6以后將SpringMVC 默認(rèn)路徑匹配策略從AntPathMatcher 更改為PathPatternParser
Springfox 使用的路徑匹配是基于AntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
<!-- swagger-annotations -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.0</version>
</dependency>
2.3.0.0版本swagger2訪問(wèn)地址為:http://localhost:8034/swagger-ui.index.html 3.0.0以下訪問(wèn)地址為:http://localhost:8034/swagger-ui.html#/
3.配置中的.enable(true)設(shè)置為true
@Bean
public Docket docket() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.spring_mybatis.base.controller"))
.paths(PathSelectors.any())
//.build().securityContexts(securityContexts())
//.build().securitySchemes(securitySchemes())
.build().enable(true); //是否啟用
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("接口大全")
.description(initContextInfo())
.version("V1.0")
.build();
}
private String initContextInfo() {
return "REST API 設(shè)計(jì)在細(xì)節(jié)上有很多自己獨(dú)特的需要注意的技巧,并且對(duì)開(kāi)發(fā)人員在構(gòu)架設(shè)計(jì)能力上比傳統(tǒng) API 有著更高的要求。" +
"<br/> 本文通過(guò)翔實(shí)的敘述和一系列的范例,從整體結(jié)構(gòu),到局部細(xì)節(jié),分析和解讀了為了提高易用性和高效性," +
"REST API 設(shè)計(jì)應(yīng)該注意哪些問(wèn)題以及如何解決這些問(wèn)題。";
}
4.配置webmvcconfig
@Slf4j
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {
@Autowired
ComponentDirectoryPathReader pathReader;
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
String filePath = "C:\\Users\\Administrator\\Desktop";
log.info("filePath:"+filePath);
registry.addResourceHandler("/**").
addResourceLocations("classpath:/static/").addResourceLocations("classpath:META-INF/resources/").
addResourceLocations("file:"+filePath);
}
}
5.配置項(xiàng)確定正確文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-513641.html
public Docket docket() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.spring_mybatis.base.controller"))//你配置swagger掃描的controller
.paths(PathSelectors.any())
//.build().securityContexts(securityContexts())
//.build().securitySchemes(securitySchemes())
.build().enable(true); //是否啟用
}
6.springboot位指定配置文件時(shí),默認(rèn)使用 application.yml文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-513641.html
到了這里,關(guān)于springboot2.7以上版本配置swagger3.0.0版本瀏覽器無(wú)法打開(kāi)swagger-ui的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!