Swagger reference may be integrated before Spring Boot articles: Spring Boot integrated Swagger 2 , arranged in each micro service with the same; this paper is only disposed in Zuul
Add the configuration in the project Zuul
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Autowired
ZuulProperties properties;
@Primary
@Bean
public SwaggerResourcesProvider swaggerResourcesProvider() {
return () -> {
List<SwaggerResource> resources = new ArrayList<>();
properties.getRoutes().values().stream()
.forEach(route -> resources
.add(createResource(route.getServiceId(), route.getServiceId(), "2.0")));
return resources;
};
}
private SwaggerResource createResource(String name, String location, String version) {
SwaggerResource swaggerResource = new SwaggerResource();
swaggerResource.setName(name);
swaggerResource.setLocation("/" + location + "/v2/api-docs");
swaggerResource.setSwaggerVersion(version);
return swaggerResource;
}
}
Wherein / v2 / api-docs of the api Swagger
test
Visit http: // localhost: 8762 / swagger -ui.html to see the effect (8762 Zuul port project)
Precautions
- Each micro service can not rely on references swagger-ui package, only in reference to the project Zuul
- If the micro services using Spring Security need a release / v2 / api-docs
Reference: Sample-Zuul-swagger2
Complete code: GitHub