配置Swaggr
1、Swagger实例Bean是Docket,所以通过配置Docket实例来配置Swaggger。
package com. xxxx. swagger2. config; import org. springframework. context. annotation. Bean;
import org. springframework. context. annotation. Configuration;
import springfox. documentation. service. ApiInfo;
import springfox. documentation. service. Contact;
import springfox. documentation. service. VendorExtension;
import springfox. documentation. spi. DocumentationType;
import springfox. documentation. spring. web. plugins. Docket;
import springfox. documentation. swagger2. annotations. EnableSwagger2; import java. util. ArrayList; import static springfox. documentation. service. ApiInfo. DEFAULT_CONTACT; @Configuration
@EnableSwagger2
public class SwaggerConfig { @Bean public Docket docket ( ) { return new Docket ( DocumentationType. SWAGGER_2) . apiInfo ( apiInfo ( ) ) ; } private ApiInfo apiInfo ( ) { Contact contact = new Contact ( "firetang" , "http://wwww.baidu.com" , "123132@qq.com" ) ; return new ApiInfo ( "firetangApidocument" , "the author is very cool" , "1.0" , "http://www.baidu.com" , contact, "Apache 2.0" , "http://www.apache.org/licenses/LICENSE-2.0" , new ArrayList < VendorExtension> ( ) ) ; } }
测试