1,添加配置类
@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文件
<!--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 服务对应端口号