Java挥舞着JaxRS抛出错误 [英] Java swagger with JaxRS throwing errors

查看:112
本文介绍了Java挥舞着JaxRS抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照此处找到的指南进行操作: https://github.com/wordnik/swagger-core/wiki/Java -JAXRS-快速入门

I followed the guide found here: https://github.com/wordnik/swagger-core/wiki/Java-JAXRS-Quickstart

这是我的POM:

<!--  SWAGGER -->
<dependency>
  <groupId>com.wordnik</groupId>
  <artifactId>swagger-jersey-jaxrs_2.10</artifactId>
  <version>1.3.0</version>
</dependency>

发现注释很好,所以我假设P​​OM运行正常

The Annotations are found fine, so i am assuming the POM is working OK

对于WEB.xml,我尝试按照指南进行多项操作:

For WEB.xml, I tried doing multiple things, following the guide:

 <servlet>
            <servlet-name>jersey-serlvet</servlet-name>
            <servlet-class>
                com.sun.jersey.spi.spring.container.servlet.SpringServlet
            </servlet-class>
            <init-param>
                <param-name>com.sun.jersey.config.property.packages</param-name>
                <param-value>com.thomsonreuters.ips.service;com.wordnik.swagger.jersey.listing</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>jersey-serlvet</servlet-name>
            <url-pattern>/service/*</url-pattern>
        </servlet-mapping>

<!-- SWAGGER serverlet? -->
<servlet>
          <servlet-name>JerseyJaxrsConfig</servlet-name>
          <servlet-class>com.wordnik.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
          <init-param>
            <param-name>api.version</param-name>
            <param-value>1.0.0</param-value>
          </init-param>
          <init-param>
            <param-name>swagger.api.basepath</param-name>
            <param-value>http://localhost:8080/{PROJECTNAME}</param-value>
          </init-param>
          <load-on-startup>2</load-on-startup>
        </servlet>

但是当我尝试到达时会抛出一个错误:

but this throws a wild error when i try to reach:

localhost:8080/{PROJECTNAME}/service/api-docs

localhost:8080/{PROJECTNAME}/service/api-docs

HTTP Status 500 - java.lang.NoSuchMethodError: com.wordnik.swagger.annotations.ApiOperation.authorizations()Ljava/lang/String;

接下来,我在googleverse周围看到了将web.xml修改为以下内容的

next I saw around the googleverse to modify the web.xml to the following:

<servlet>
        <servlet-name>jersey-serlvet</servlet-name>
        <servlet-class>
            com.sun.jersey.spi.spring.container.servlet.SpringServlet
        </servlet-class>
         <init-param>
            <param-name>api.version</param-name>
            <param-value>2.0</param-value>
          </init-param>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.thomsonreuters.ips.service;com.wordnik.swagger.jaxrs;</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/service/*</url-pattern>
    </servlet-mapping>

请注意api.version和新的jaxrs init参数.

note the api.version and the new jaxrs init param.

发生这种情况时,我去

http://localhost:8080/ScholarlyItemService/service/api-docs 

我没有收到任何错误,但我确实得到了无用的网页:

i get no errors, but i do get useless webpage:

{"apiVersion":"0.0","swaggerVersion":"1.2"}

推荐答案

我想您差不多了.您看到的不是一个无用的网页,而是由swagger作为json文档构建的服务文档.您必须按照快速入门指南中的说明对代码进行注释.这应该显示在此文档中.

I think you almost have it. What you see is not a useless webpage, it's rather the documentation of your service built by swagger as a json document. You have to annotate your code as shown in the Quickstart guide. This should show up in this document.

您可能真正想要的是Swagger UI: http://swagger.wordnik.com/到以可读的方式查看此文档.

What you may actually want is the Swagger UI: http://swagger.wordnik.com/ to see this document in a readable way.

花了我一会儿,但我开始运行了.您必须从此处下载: https://github.com/wordnik/swagger-ui ,并将内容从dist文件夹复制到/webapp文件夹.然后,您可以在浏览器中打开包含的index.html.就我而言,我无法直接访问此文档,因此必须将dist的内容放在子文件夹(例如/docs)中,并将其从web.xml中的servlet映射中排除,如下所述:

It took me a moment, but I got it running. You have to download from here: https://github.com/wordnik/swagger-ui, and copy the contents from the dist folder to your /webapp folder. You can then open the contained index.html in a browser. In my case, I could not access this document directly, so I had to put the dist' contents in a subfolder (e.g. /docs) and exclude this from my servlet mapping in web.xml as described here: http://blog.ericdaugherty.com/2010/02/excluding-content-from-url-pattern-in.html.

在index.html中,更改网址:" http://petstore.swagger. wordnik.com/api/api-docs ", 到您的api端点http://localhost:8080/ScholarlyItemService/service/api-docs的一部分,调用http://localhost:8080/ScholarlyItemService/docs/index.html

In the index.html change the url: "http://petstore.swagger.wordnik.com/api/api-docs", part to your api endpoint http://localhost:8080/ScholarlyItemService/service/api-docs and you will get your api documentation when calling http://localhost:8080/ScholarlyItemService/docs/index.html

这篇关于Java挥舞着JaxRS抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆