1,添加配置類html
@Configuration @EnableSwagger2 @Profile({"default", "dev-online", "test"}) public class SwaggerConfiguration { @Bean public Docket appDoc() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(appApiInfo()) .directModelSubstitute(Date.class, Double.class) .directModelSubstitute(LocalDate.class, Double.class) .select() .apis(RequestHandlerSelectors.basePackage("com.example.multidatasource.web"))//換成對應應用入口層級 .paths(PathSelectors.any()) .build(); } private ApiInfo appApiInfo() { return new ApiInfoBuilder() .title("plan-warehousing 接口文檔") .version("1.0.0") .build(); } }
2,添加pom文件java
<!--swagger支持 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>swagger-bootstrap-ui</artifactId> <version>1.9.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.7.0</version> </dependency>
3,瀏覽器訪問http://localhost:80/doc.html 服務對應端口號git