Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.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 Jersey JAX-RS,Swagger-生成Swagger.json但没有UI_Java_Rest_Jersey_Swagger_Swagger Ui - Fatal编程技术网

Java Jersey JAX-RS,Swagger-生成Swagger.json但没有UI

Java Jersey JAX-RS,Swagger-生成Swagger.json但没有UI,java,rest,jersey,swagger,swagger-ui,Java,Rest,Jersey,Swagger,Swagger Ui,我在加载Swigger UI/启用UI端点时遇到问题。 Maven项目,泽西岛版本-2.12,大摇大摆版本-1.5.1-M2 我有一个编程配置的jersey web应用程序。 在我的ResourceConfig扩展中,我为Swagger设置了以下内容: beanConfig=新的beanConfig; beanConfig.setVersion1.0.0; beanConfig.setHosthttp:localhost:8080; beanConfig.setBasePath/app/v1;

我在加载Swigger UI/启用UI端点时遇到问题。 Maven项目,泽西岛版本-2.12,大摇大摆版本-1.5.1-M2

我有一个编程配置的jersey web应用程序。 在我的ResourceConfig扩展中,我为Swagger设置了以下内容:

beanConfig=新的beanConfig; beanConfig.setVersion1.0.0; beanConfig.setHosthttp:localhost:8080; beanConfig.setBasePath/app/v1; beanConfig.setResourcePackagecom.app.features; beanConfig.setScantrue;
 registerbeanConfig; 注册新ApiListingResourceJSON; registernew-SwaggerSerializers; 我还有一个bootscrap类,通过web.xml加载:

public class Bootstrap extends HttpServlet {

  @Override
  public void init(ServletConfig config) throws ServletException {
    Info info = new Info()
            .title("Swagger Sample App")
            .description("Desc")
            .termsOfService("http://helloreverb.com/terms/")
            .contact(new Contact()
                    .email("apiteam@swagger.io"))
            .license(new License()
                    .name("Apache 2.0")
                    .url("http://www.apache.org/licenses/LICENSE-2.0.html"));

    ServletContext context = config.getServletContext();
    Swagger swagger = new Swagger().info(info);
    context.setAttribute("swagger", swagger);
  }
}
Said web.xml:

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>

  <servlet>
    <servlet-name>Bootstrap</servlet-name>
    <servlet-class>com.app.Bootstrap</servlet-class>
    <load-on-startup>2</load-on-startup>
  </servlet>
但我似乎没有在我期望的http:localhost:8080/app/v1或http:localhost:8080/app/v1/app/v1/index.html路径上看到招摇过市的UI

不幸的是,我对泽西的感觉不如对斯普林的感觉舒服,所以欢迎任何帮助

谢谢

您需要下载web项目,并将其放在web目录中,然后在index.html中配置api地址

index.html:


现在您可以通过访问http://ip:port/path/swagger-ui/index.html。

我们也在google组中讨论它,但这很可能是因为您的资源不是直接位于com.app.features包之下,而是一个子包,如com.app.features.foo。如果它们跨越多个包,您可以将它们设置为com.app.features.foo、com.app.features.bar

我相信深度扫描在1.5.2-M2中进行了更改,所以您也可以尝试一下。

在以下方面有一个输入错误:

beanConfig.setHost("http:localhost:8080");
应该是:

beanConfig.setHost("http://localhost:8080");
如果您使用的是Maven,是否可以尝试包含swagger uidependency:

<dependency>
  <groupId>org.webjars</groupId>
  <artifactId>swagger-ui</artifactId>
  <version>2.2.10-1</version>
</dependency>
或者更新的版本

并尝试在浏览器中打开此url:


http://localhost:8080/app/v1/api-docs?url=/app/v1/swagger.json

请查找以下工作示例

包com.vk.test.swagger

import static springfox.documentation.builders.PathSelectors.regex;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2

/**
 * 
 * @author vaquar khan
 *
 */
public class SwaggerConfiguration {
    @Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2).select()
                .apis(RequestHandlerSelectors.basePackage("com.vk.test.controller")).paths(regex("/api/apiPath.*"))
                .build();

    }

}
马文

招摇过市

http://<servername>:<Port>/swagger-ui.html

我做了这件事,但毫无效果。我认为它不是一个正确暴露的端点。Curl什么也不返回。只有路径+/swagger.json和我的api端点会做出相反的响应。您的访问路径是什么?我认为你的道路应该是http://localhost:8080/app/v1/app/v1/swagger-ui/index.html。swagger ui文件夹应该存在于index.html文件夹中。我们是否可能讨论不同版本的swagger ui?对我来说,webapp文件夹有新的Swagger index.html、Swagger-ui.js文件、css和字体文件夹,你可以在这里看到:尝试访问路径:这个对我来说没有意义,但没有任何作用。这感觉像是一个端点问题。
import static springfox.documentation.builders.PathSelectors.regex;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2

/**
 * 
 * @author vaquar khan
 *
 */
public class SwaggerConfiguration {
    @Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2).select()
                .apis(RequestHandlerSelectors.basePackage("com.vk.test.controller")).paths(regex("/api/apiPath.*"))
                .build();

    }

}
   <!-- Swagger -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
            <scope>compile</scope>
        </dependency>
        <!-- Swagger UI -->

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
            <scope>compile</scope>
        </dependency>
http://<servername>:<Port>/swagger-ui.html