swagger2.9.2 和 springboot3.3.4版本冲突问腿
问题描述:当我们使用 swagger 2.9.2版本的时候,如果恰好我们使用的 springboot 版本是3.x版本,会出现启动报错的问题
解决办法:直接使用swagger 3.x 版本和 springboot 3.x 版本
解决步骤:
1.导入swagger3.x版本的maven依赖
< dependency>
< groupId> org. springdoc< / groupId>
< artifactId> springdoc- openapi- starter- webmvc- ui< / artifactId>
< version> 2.2 . 0 < / version>
< / dependency>
2.在config包中加入swaager配置类
package com. example. demo. config;
import io. swagger. v3. oas. models. ExternalDocumentation;
import io. swagger. v3. oas. models. OpenAPI;
import io. swagger. v3. oas. models. info. Contact;
import io. swagger. v3. oas. models. info. Info;
import io. swagger. v3. oas. models. info. License;
import org. springframework. context. annotation. Bean;
import org. springframework. context. annotation. Configuration;
@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI springShopOpenAPI ( ) {
return new OpenAPI ( )
. info ( new Info ( ) . title ( "标题" )
. contact ( new Contact ( ) )
. description ( "我的API文档" )
. version ( "v1" )
. license ( new License ( ) . name ( "Apache 2.0" ) . url ( "http://springdoc.org" ) ) )
. externalDocs ( new ExternalDocumentation ( )
. description ( "外部文档" )
. url ( "https://springshop.wiki.github.org/docs" ) ) ;
}
}
3.启动项目访问swagger
http: