问题
I want to use Swagger with Spring MVC. I have following entries in the build.gradle file
compile 'com.mangofactory:swagger-springmvc:0.9.4'
compile 'com.wordnik:swagger-annotations:1.3.12'
compile 'org.webjars:swagger-ui:2.0.12'
I have enable it using @EnableSwagger annotation.
@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("/");
}
}
But when run the application using spring boot and hit the endpoint http://localhost:8080/api-docs, I just see the response in 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"}
I copied the static files from swagger-ui and copied it to my /main/webapp/doc
I am still missing fancy UI.
来源:https://stackoverflow.com/questions/28178370/swagger-not-showing-ui