Swagger:没有显示UI

时间:2015-01-27 19:22:38

标签: spring-mvc swagger swagger-ui

我想在Spring MVC中使用Swagger。我在build.gradle文件中有以下条目

 compile 'com.mangofactory:swagger-springmvc:0.9.4'
 compile 'com.wordnik:swagger-annotations:1.3.12'
 compile 'org.webjars:swagger-ui:2.0.12'

我已使用@EnableSwagger注释启用它。

@EnableAutoConfiguration(exclude = {EmbeddedServletContainerAutoConfiguration.EmbeddedJetty.class, LiquibaseAutoConfiguration.class, org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class})
@EnableSwagger
@EnableWebMvc
@Configuration
public class App extends WebMvcConfigurerAdapter{
    @Bean
    ProtobufHttpMessageConverter protobufHttpMessageConverter() {
        return new ProtobufHttpMessageConverter();
    }

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }

    private SpringSwaggerConfig springSwaggerConfig;

    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {
        this.springSwaggerConfig = springSwaggerConfig;
    }

    @Bean
    public SwaggerSpringMvcPlugin customImplementation(){

        return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
                .apiInfo(apiInfo())
                .includePatterns(".*feed.*"); // assuming the API lives at something like http://myapp/api
    }

    private ApiInfo apiInfo() {
        ApiInfo apiInfo = new ApiInfo(
                "My Project's REST API",
                "This is a description of your API.",
                "API TOS",
                "me@wherever.com",
                "API License",
                "API License URL"
        );
        return apiInfo;
    }

    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("*.html").addResourceLocations("/");
    }
}

但是当使用spring boot运行应用程序并点击端点http://localhost:8080/api-docs时,我只看到Json中的响应,

{"apiVersion":"1.0","apis":[{"description":"Basic Error Controller","path":"/default/basic-error-controller","position":0},{"description":"Manage people","path":"/default/people","position":0}],"authorizations":{},"info":{"contact":"Contact Email","description":"Api Description","license":"Licence Type","licenseUrl":"License URL","termsOfServiceUrl":"Api terms of service","title":"default Title"},"swaggerVersion":"1.2"}

我从swagger-ui复制了静态文件并将其复制到我的/ main / webapp / doc

我仍然缺少精美的UI。

0 个答案:

没有答案