Added Springfox Swagger-UI and it's not working, what am I missing?

后端 未结 11 1499
甜味超标
甜味超标 2020-12-02 00:00

Following the instructions here:

http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api

I added these dependencies to my project:



        
11条回答
  •  既然无缘
    2020-12-02 00:28

    If you are using Spring Boot Version >= 2.2, I recommend using SpringFox Swagger version 3.0.0. Keep your pom.xml dependency configuration like this:

    
            io.springfox
            springfox-boot-starter
            3.0.0
    
    

    Keep your Swagger configuration class like below:

    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.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    import springfox.documentation.swagger2.annotations.EnableSwagger2;
    import java.util.Arrays;
    import java.util.HashSet;
    import java.util.Set;
    
    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
    
    public static final Contact DEFAULT_CONTACT = new Contact(
            "Sample App", "http://www.sample.com", "sample@gmail.com");
    
    public static final ApiInfo DEFAULT_API_INFO = new ApiInfo(
            "Awesome API Title", "Awesome API Description", "1.0",
            "urn:tos", DEFAULT_CONTACT,
            "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", Arrays.asList());
    
    private static final Set DEFAULT_PRODUCES_AND_CONSUMES =
            new HashSet(Arrays.asList("application/json",
                    "application/xml"));
    
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(DEFAULT_API_INFO)
                .produces(DEFAULT_PRODUCES_AND_CONSUMES)
                .consumes(DEFAULT_PRODUCES_AND_CONSUMES);
     }
    }
    

    Now, access your swagger UI by going to this URL: http://localhost:8080/swagger-ui/index.html#/

提交回复
热议问题