Spring Boot更换Spring fox为Springdoc


项目场景

由于项目中使用Spring fox已经不维护更新了,代码扫描,扫出问题,需要将Spring fox更换为Spring Doc

由于我们封装的框架有个配置需要关掉,否则就会查看相关依赖,这个就不展示了。


引入

将将Spring fox依赖更换为Spring Doc

implementation 'org.springdoc:springdoc-openapi-ui:1.6.9'

使用

使用就比较简单了,直接上配置就好了。

@OpenAPIDefinition(
        info = @Info(
                    title = "SWAGGER - ${spring.profiles.active:prod} " ,
                    version = "v0.0.1",
                    description = "API Resources & Documentation",
                    contact = @Contact(
                        name="FLI86", email = "***"
                    )
        ),
        security = @SecurityRequirement(name = "SWAGGERAuthorize")
)
@SecuritySchemes({
    
    @SecurityScheme(
        name = "SWAGGERAuthorize",
        type = SecuritySchemeType.HTTP,
        description= "JWT认证",
        scheme="bearer",
        bearerFormat="JWT",
        in= SecuritySchemeIn.HEADER
)})
@Configuration
public class SpringDocConfiguration {
    
    
}

说明

  • @SecurityRequirement的name其实就是引用,引用的就是@SecuritySchemes里面的name,所以这两个要保持一致。
  • 因为我们是要用到token,所以在swagger里面配置好token之后,这边就能填入token,并直接请求了。

页面就不做展示了,涉及公司业务


打完收工!

猜你喜欢

转载自blog.csdn.net/qq_37759895/article/details/135822787