Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未调用Swagger ReaderListener_Java_Web Services_Jax Rs_Swagger_Swagger 2.0 - Fatal编程技术网

Java 未调用Swagger ReaderListener

Java 未调用Swagger ReaderListener,java,web-services,jax-rs,swagger,swagger-2.0,Java,Web Services,Jax Rs,Swagger,Swagger 2.0,我试图从ReaderListener接口调用afterScan(…)方法,但没有被调用。这是我的密码: @SwaggerDefinition( info = @Info( description = "My API", version = "V1.2.3", title = "The only API you'll ever need", termsOfService = "share and care", contact = @Contact(name

我试图从ReaderListener接口调用afterScan(…)方法,但没有被调用。这是我的密码:

@SwaggerDefinition( info = @Info(
    description = "My API",
    version = "V1.2.3",
    title = "The only API you'll ever need",
    termsOfService = "share and care",
    contact = @Contact(name = "Test-Bob", email = "test-bob@tester.io", url = "http://swagger.io"),
    license = @License(name = "Apache 2.0", url = "http://www.apache.org")))
    @Api(tags = {"something", "else"})
    @Path("/myUrl/swagger/{type:json|yaml}")
    public class MyApiListingResource extends BaseApiListingResource implements ReaderListener {

      private static final Logger logger = LoggerFactory.getLogger(MyApiListingResource.class); 

      @Context ServletContext context;

      @GET
      @Produces({MediaType.APPLICATION_JSON, "application/yaml"})
      @ApiOperation(value = "The swagger definition in either JSON or YAML", 
        hidden = true)
      public Response getListing(@Context Application app, @Context ServletConfig servletConfig, @Context HttpHeaders headers,
                @Context UriInfo uriInfo, @PathParam("type") String type) throws JsonProcessingException {

            if (isNotBlank(type) && type.trim().equalsIgnoreCase("yaml")) {

                return getListingYamlResponse(app, context, servletConfig, headers, uriInfo);

            } else {

                System.out.println("I found json!");
                logger.debug("I'm also before!!!");

                return getListingJsonResponse(app, context, servletConfig, headers, uriInfo);
            }
      }

      @Override
      public void beforeScan(Reader reader, Swagger swagger) {

      System.out.println("I'm before!!!");
      logger.debug("I'm also before!!!");

      } 

      @Override
      public void afterScan(Reader reader, Swagger swagger) {

      System.out.println("I'm after!!!");
      logger.debug("I'm also after!!!");     

      }

    }
现在,当我调用以下服务时:

http://localhost:9081/myApp/myUrl/swagger/json
我确实在控制台和日志中收到了“我找到了json!”,但控制台或日志中没有打印任何“before”或“after”注释

我使用的是Swagger 1.5.10和Java7。我会提供任何其他需要的细节

欢迎任何意见!谢谢


更新:我尝试将@SwaggerDefinition注释添加到这个类中,如上图所示,但仍然不起作用


你知道我遗漏了什么吗?

我终于找到了问题所在。显然,原始设计的问题在于,我在试图实现ReaderListener的同一个类上扩展了
BaseApiListingResource
。无论出于何种原因(如果您知道原因,请随意评论),
ReaderListener
在我扩展
BaseApiListingResource
时不起作用。如果我在一个不扩展
BaseApiListInSource
的类上实现
ReaderListener
,那么
在扫描前
和扫描后
都可以正常工作

希望这对某人有帮助