无法读取昂首阔步的JSON

时间:2015-02-26 21:02:41

标签: spring rest swagger swagger-ui

我已按照以下链接使用Swagger with Spring为我的REST服务创建API文档。

http://jakubstas.com/spring-jersey-swagger-configuration/#comment-1726

一切顺利,但当我尝试使用网址http://localhost:8080/rest/api-docs访问api文档时,我得到无法读取招摇的JSON 。有人可以帮忙吗?

4 个答案:

答案 0 :(得分:0)

Swagger不在当地工作! 您可以下载本地的Swagger Ui

答案 1 :(得分:0)

你试试这种方式。

@Configuration
@EnableSwagger
// Loads the spring beans required by the framework
public class MySwaggerConfig
{

    private SpringSwaggerConfig springSwaggerConfig;

    /**
     * Required to autowire SpringSwaggerConfig
     */
    @Autowired
    public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig)
    {
        this.springSwaggerConfig = springSwaggerConfig;
    }

    /**
     * Every SwaggerSpringMvcPlugin bean is picked up by the swagger-mvc
     * framework - allowing for multiple swagger groups i.e. same code base
     * multiple swagger resource listings.
     */
    @Bean
    public SwaggerSpringMvcPlugin customImplementation()
    {
        return new SwaggerSpringMvcPlugin(this.springSwaggerConfig).apiInfo(apiInfo()).includePatterns(
                ".*?");
    }

    private ApiInfo apiInfo()
    {
        ApiInfo apiInfo = new ApiInfo(
                "xx", 
                "xxxx",
                "My Apps API terms of service", 
                "xxx",
                null,
                null);
        return apiInfo;
    }
}







 <dependency>
                <groupId>com.mangofactory</groupId>
                <artifactId>swagger-springmvc</artifactId>
                <version>0.9.5</version>
            </dependency>

答案 2 :(得分:0)

我通过将下一个文件添加到资源文件夹

解决了这个问题
  

swagger.properties

添加了属性:

  

springfox.documentation.swagger.v2.path = / API / swagger.json

然后在代码中添加:

@Configuration
@EnableSwagger2
@PropertySource(value = "classpath:swagger.properties")
public class PathConfiguration {
@Value("${springfox.documentation.swagger.v2.path}")
private String swagger2Endpoint;

然后用于Dockect配置的bean简单bean,如:

@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any())
            .build();
}

答案 3 :(得分:0)

它将导致以下问题:

@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .groupName("Swagger Group One API")
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.xingyun"))
            .paths(PathSelectors.any())
            .build();
}

固定如下是可以的

@Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("SwaggerGroupOneAPI")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xingyun"))
                .paths(PathSelectors.any())
                .build();
    }