Springfox swagger - 没有 Spring Boot jersey 和 gradle 的 api 文档

2023-12-05

我有一个带有 jersey 和 gradle 的 spring boot 应用程序,我正在尝试使用 springfox 自动生成 API 文档。

我已按照此处的步骤操作:http://springfox.github.io/springfox/docs/current/

这是我所做的:

  • 构建.gradle:

    dependencies {
        .........
        //Swagger
        compile "io.springfox:springfox-swagger2:2.4.0"
        compile "io.springfox:springfox-bean-validators:2.4.0"
        compile 'io.springfox:springfox-swagger-ui:2.4.0'
    }
    
  • 春季启动应用:

    @SpringBootApplication
    @EnableSwagger2
    public class AnalyzerServiceApplication{
    
    public static void main(String[] args) {
        SpringApplication.run(AnalyzerServiceApplication.class, args);
    }
    
    @Bean
    public Docket analyzerApi() {
    return new Docket(DocumentationType.SWAGGER_2)
    .select()
        .apis(RequestHandlerSelectors.any())
        .paths(PathSelectors.any())
        .build()
    .pathMapping("/")
    .directModelSubstitute(LocalDate.class, String.class)
    .genericModelSubstitutes(ResponseEntity.class)
    .alternateTypeRules(
        newRule(typeResolver.resolve(DeferredResult.class,
        typeResolver.resolve(ResponseEntity.class, WildcardType.class)),
        typeResolver.resolve(WildcardType.class)))
    .useDefaultResponseMessages(false)
    .globalResponseMessage(RequestMethod.GET,
        newArrayList(new ResponseMessageBuilder()
            .code(500)
            .message("500 message")
            .responseModel(new ModelRef("Error"))
            .build()))
    .securitySchemes(newArrayList(apiKey()))
    .securityContexts(newArrayList(securityContext()))
    .enableUrlTemplating(true)
    .globalOperationParameters(
        newArrayList(new ParameterBuilder()
            .name("someGlobalParameter")
            .description("Description of someGlobalParameter")
            .modelRef(new ModelRef("string"))
            .parameterType("query")
            .required(true)
            .build()))
        .tags(new Tag("Pet Service", "All apis relating to pets")) 
        ;
    }
    
    @Autowired
    private TypeResolver typeResolver;
    
    private ApiKey apiKey() {
        return new ApiKey("mykey", "api_key", "header");
    }
    
    private SecurityContext securityContext() {
        return SecurityContext.builder()
            .securityReferences(defaultAuth())
            .forPaths(PathSelectors.regex("/anyPath.*"))
            .build();
    }
    
    List<SecurityReference> defaultAuth() {
        AuthorizationScope authorizationScope
            = new AuthorizationScope("global", "accessEverything");
            AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
        authorizationScopes[0] = authorizationScope;
        return newArrayList(
            new SecurityReference("mykey", authorizationScopes));
    }
    
    @Bean
    SecurityConfiguration security() {
        return new SecurityConfiguration(
            "test-app-client-id",
            "test-app-client-secret",
            "test-app-realm",
            "test-app",
            "apiKey",
            ApiKeyVehicle.HEADER, 
            "api_key", 
            "," /*scope separator*/);
    }
    
    @Bean
    UiConfiguration uiConfig() {
        return new UiConfiguration("validatorUrl");
    }
    
  • 现在是控制器(泽西岛)

    @Api(value = "/widget")
    @Path("/widget")
    @Component
    public class WidgetController extends BaseController {
    
    @Autowired
    private WidgetService widgetService;
    
    @GET
    @Path("/secHealth")
    @ApiOperation(value = "Find pet by ID", notes = "Returns a pet when ID < 10.  ID > 10 or nonintegers will simulate API error conditions", response = Pet.class)
    @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"),
    @ApiResponse(code = 404, message = "Pet not found") })
    public Response getPet() {
        //Do something
    }
    

当我启动服务器并导航到http://localhost:8080/swagger-ui.html,我可以看到“绿色”UI 屏幕,其中仅列出了基本错误控制器。我自己的控制器不在那里。

我做错了什么? 谢谢 盖伊


截至版本2.5.0 春狐仅支持 spring-mvc 控制器。不支持 jersey 等 Jax-rs 实现。

当前使用 springfox 的替代方法是使用招摇核心基于 jax-rs/jersey 的服务的库。

它确实具有实现对球衣的支持所需的挂钩2.6+。这是实现它的方法的摘录这个问题

目前 ResourceConfig 有一个名为“getClasses”的方法,它将 列出所有已注册的内容。比如资源、过滤器等...也许这个 有帮助。但请注意,返回的课程也可能是 过滤器或任何其他可以在 jersey2 上注册的东西。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Springfox swagger - 没有 Spring Boot jersey 和 gradle 的 api 文档 的相关文章

随机推荐

  • 常量缓冲区的aligned_malloc() 与alignas()

    在C 中 我们有关键字alignas n 我们有 aligned malloc m n 功能 alignas作用于类型 同时aligned malloc无论你怎么称呼它 都可以工作 我可以用吗alignas 16 满足 Direct3D 常
  • 选择Android开发SDK位置时需要指定哪个文件夹?

    在 LiveCode 中设置移动支持首选项以开发 Android 时 哪个文件夹内安卓文件夹需要选择存档吗 每当我选择一个文件夹时 似乎都会出现一条错误消息 The chosen folder is not a valid Android
  • 无法从 Android 中的 Firebase Storage 获取下载网址[重复]

    这个问题在这里已经有答案了 无法从 Android 中的 Firebase 存储获取下载网址 我得到 com google android gms tasks zzn 而不是 url 下载链接 我的代码 storageReference g
  • 关于问号“惰性”模式的正则表达式

    我明白了 这里mark的意思是 懒惰 我的问题本质上是 0 9 2 vs 0 9 2 它们相同吗 如果是这样 我们为什么要写前一个表达式 惰性模式不是更昂贵的性能吗 如果不是 你能分辨出区别吗 什么是 懒惰 不情愿 匹配 与正则表达式匹配时
  • 回收站视图中的项目重叠

    当用户滚动时 我的回收器视图中的项目会重叠 注意底部重叠的文本 这是生成此视图的代码 ArrayList
  • 缓冲区之间的 Emacs 选项卡

    有没有一种方法可以在缓冲区之间切换而无需通过 buffer list 或者写入我想要切换到的缓冲区的名称 更具体地说 我想知道 emacs 是否可以在缓冲区之间进行制表 就像它在 notepad 中的工作方式一样 Emacs 22 1 及更
  • 使用“auto”的声明是否与使用具体类型说明符的 extern 声明匹配?

    考虑以下程序 extern int x auto x 42 int main Clang 3 5 接受它 现场演示 GCC 4 9 和 VS2013 没有 前者的现场演示 谁是对的 C 标准中规定的正确行为在哪里 令人惊讶的是 标准中对此的
  • 复杂的 Mongoose 过滤查询

    我正在构建一个允许用户使用侧边栏过滤结果的网站 他们选择的标准越多 搜索结果就应该越具体 见附图 用户可以选择与他们要查找的内容相匹配的过滤器 复选框 我为此使用 MongoDB 我的架构如下 brandName type String r
  • Raspberry pi 4 用 java 控制 GPIO

    我想用java控制我的树莓派4上的16 2液晶显示屏 问题是Pi4J 用java修改gpios的解决方案没有更新到pi4 还有其他解决方案吗 当我启动程序时出现此错误 pi raspberrypi desktop gpio sudo sta
  • 如何在 Yii 中为单个日期属性设置多个字段(D/M/Y)?

    我想将用户出生日期存入我的数据库 表中有一个字段称为dob 当我创建模型和 CRUD 时 它生成了文本字段dob一如既往 但我想创建三个输入 多年 几个月来 和日期 所以我的问题是如何在模型的表单中添加额外的输入 我正在考虑向模型类添加新属
  • iPhone可以与JMS通信吗?

    只是想知道是否有人知道如何在 iPhone 和 iPhone 之间发送 接收 XML 消息Java消息服务 Regards 有几种方法可以实现这一点 要么通过 MQ 附带的 HTTP 桥 我自己已经这样做了 要么使用新的 MQTT 支持 您
  • MKMapView持续监控航向

    我在位于我的顶部的图层中渲染一些内容MKMapView 除了旋转之外 整个事情都运转良好 当用户旋转地图时 我需要能够旋转我在自己的图层中渲染的内容 我发现的标准答案是使用 NSLog heading f self mapView came
  • mozilla 和 safari 的仪表栏样式

    I am using the following css on my meter bars but somehow the styling does not work on safari see below screenshots I am
  • 如何停止 while 循环

    这个 while 循环永远不会结束 例如 当我输入错误的密码时 它会一遍又一遍地进入 密码错误 部分 Logo inFile open UsernamePassword txt if inFile cout lt lt Unable to
  • 在http标头中设置身份验证令牌

    我一直在关注关于如何设置身份验证令牌的railscasthttp railscasts com episodes 352 securing an api view asciicast 我已经很好地设置了我的应用程序 它使用authentic
  • 获取字符串的每个组合

    我有一个组合学作业 涉及从特定的字符串组合中获取长度小于或等于 6 的每个单词 在本例中 它是 S a ab ba 教授刚刚开始列出它们 但我认为用程序来解决会更容易 唯一的问题是我无法得到一个好的算法来实际计算每个可能的选项 如果有人可以
  • Onchange 事件运行不佳

    我创建了以下 html 页面
  • 必须使用 fibo_ 实例作为第一个参数调用未绑定方法 f() (改为使用 classobj 实例)

    在 Python 中 我尝试在类中运行一个方法 但出现错误 Traceback most recent call last File C Users domenico Desktop py main py line 8 in
  • 将 sqlite3 db 关联到 iPhone 应用程序

    我正在尝试将 SQLite3 数据库文件与我们的应用程序关联起来 以便可以轻松地从电子邮件打开备份的数据库 然而 以下内容似乎不起作用 因为 邮件 仍然无法识别该文件 在 iPad 和 iPhone 4 上
  • Springfox swagger - 没有 Spring Boot jersey 和 gradle 的 api 文档

    我有一个带有 jersey 和 gradle 的 spring boot 应用程序 我正在尝试使用 springfox 自动生成 API 文档 我已按照此处的步骤操作 http springfox github io springfox d