当前位置:网站首页>Knife4j configuration can use direct copy

Knife4j configuration can use direct copy

2022-06-10 20:28:00 Hehexue programming

I won't say more nonsense , Go straight up maven rely on

<!-- knife4j Interface document  -->
<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>knife4j-spring-boot-starter</artifactId>
    <version>3.0.3</version>
</dependency>

Then write a configuration class Knife4jConfig, To avoid the wrong package , I gave you my bag, too

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Knife4jConfig {
    

    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
    
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("xxx Interface specification ")
                        .description("xxx Interface description ")
                        .termsOfServiceUrl("http://www.xx.com/")
                        .contact(new Contact("xxx company ", "http://xxx.com/", "[email protected]"))
                        .version("1.0")
                        .build())
                // Group name 
                .groupName("2.X edition ")
                .select()
                // Designated here Controller Scan package path 
                .apis(RequestHandlerSelectors.basePackage("com.xxx.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}

Run project access http://localhost:8080/doc.html

原网站

版权声明
本文为[Hehexue programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101921305260.html