Tips for springboot Update Configuration of Swagger3

  • 2021-10-16 01:37:02
  • OfStack

1. Introduce dependencies, only one in version 3.0. 0


<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

2. Configure the class SwaggerConfig


package org.fh.config;

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.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 *  Description: Swagger  Interface API Generate 
 *  By: FH Admin
 * from fhadmin.cn
 */
@Configuration
@EnableOpenApi
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("org.fh.controller"))    //  Is the current package path 
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("FH Admin Swagger3 RESTful API")     //  Page title 
                .version("3.0")                                //  Version number 
                .description("fhadmin.org")                    //  Describe 
                .build();
    }

}

3. Swagger interception configuration


package org.fh.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *  Description: Swagger  Intercept configuration 
 *  By: FH Admin
 * from fhadmin.cn
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.
                addResourceHandler("/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
                .resourceChain(false);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/swagger-ui/")
                .setViewName("forward:/swagger-ui/index.html");
    }
}

4. Visit  127.0.0.1:8081/swagger-ui/index.html

5. Interface description case 

 Handle annotations on classes, such as 
@Api(" User registration login interface ")

 Annotate methods, such as 
@ApiOperation(value = " Login ", notes=" Verify that the login is successful ")
@ApiImplicitParam(name = "KEYDATA", value = " User name password aliasing code combination ", paramType = "query", required = true, dataType = "String")

Workflow module--------------------------------------------------------------

1. Model management: web online process designer, import and export xml, copy process, deploy process

2. Process management: Import and export process resource files, view the flow chart, reflect the process model according to the process instance, and activate pending

3. Running process: View process information, current task node, current flow chart, void and suspend process, assign to-do person, and jump freely

4. Historical process: View process information, process time, process status, and task initiator information

5. To-do tasks: View my personal tasks and tasks under this role, process, reject, void, and assign 1 agent

6. Tasks done: Check the tasks you have handled, as well as the process information, flow chart and process status (voided, rejected and completed normally)

You can select a user to send a copy when processing a task, that is, send an in-station letter to the copied person to notify the current approval comments and remarks

Note: When the current task is completed, the next task backlog will receive a new task message reminder by instant messaging. When the task is cancelled and completed,

The task initiator will receive an in-site message notification


Related articles: