spring boot 集成 swagger2步骤
1 maven依赖
<dependency> <groupId></groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.6.1</version> </dependency> <dependency> <groupId></groupId> <artifactId>springfox-swagger2</artifactId> <version>2.6.1</version> </dependency>
2:配置类
@EnableSwagger2 @EnableWebMvc @Configuration public class SwaggerConfig { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(("")) // 注意修改此处的包名 .paths(()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("接口列表 v1.1.0") // 任意,请稍微规范点 .description("接口测试") // 任意,请稍微规范点 .termsOfServiceUrl("http://localhost:8080/项目名称/") // 将“url”换成自己的ip:port .contact("ccccc") // 无所谓(这里是作者的别称) .version("1.1.0") .build(); } }
3 网上很多教程做到这里,就完成了,但是我发布时候找不到,所以多加了一个配置
@Configuration class WebMvcConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { ("") .addResourceLocations("classpath:/META-INF/resources/"); ("/webjars/**") .addResourceLocations("classpath:/META-INF/resources/webjars/"); } }