当前位置: 代码迷 >> 综合 >> Springboot + Swagger2.9.2
  详细解决方案

Springboot + Swagger2.9.2

热度:72   发布时间:2023-10-31 07:28:14.0

目录

application.yml

pom.xml

 SwaggerConfig

MyWebAppConfiguration


application.yml

#swagger接口文档
swagger:enabled: true

pom.xml

 <!--swagger2 依赖--><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.9.2</version></dependency><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.9.2</version></dependency><dependency><groupId>io.swagger</groupId><artifactId>swagger-annotations</artifactId><version>1.5.19</version></dependency>

 SwaggerConfig

config文件夹创建,包名改成自己的

package com.cei.xyd.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;/*** @author * @version */
@Configuration
@EnableSwagger2
public class SwaggerConfig {@Beanpublic Docket DApi() {return new Docket(DocumentationType.SWAGGER_2).groupName("文档名").apiInfo(apiInfo()).forCodeGeneration(true);}/*@Beanpublic Docket AApi() {return new Docket(DocumentationType.SWAGGER_2).groupName("商品A接口文档").apiInfo(apiInfoA()).forCodeGeneration(true);}*/private ApiInfo apiInfo() {return new ApiInfoBuilder().title("XYD-API").description("")// .termsOfServiceUrl("").contact(new Contact("XYD", "", "")).version("1.0").build();}/*private ApiInfo apiInfoA() {return new ApiInfoBuilder().title("Tencent-API").description("?2016 Copyright. Powered By CEI.")// .termsOfServiceUrl("").contact(new Contact("Tencent", "", "Cei@163.com")).version("2.0").build();}*/}

MyWebAppConfiguration

找到继承WebMvcConfigurerAdapter自己写的类,我的叫MyWebAppConfiguration,修改拦截避免重定向

.excludePathPatterns("/swagger-ui.html", "/webjars/**", "/**/swagger-resources/**")

截图