Why Springfox-swagger2 user interface tells me "Unable to print base url".

Why does the springfox-swagger2 user interface tell me which is not possible Unable to infer base url.As far as I know, I am using the typical spring loaded Swagger configuration.

As you can see in the screenshot, the swagger-fox URL that supports the user interface is example.com/api . NOTE. I get the standard Whitelabel Error PageSpring Whitelabel Error Pagewhen navigating to : https: // localhost: 9600 / api / v2 / api-docs / . I suspect this is the root of the problem? I see no errors in the fact that Spring did not load springfox-swagger2and therefore I do not know why this does not work.

enter image description here

( , ):

@EnableSwagger2
@EnableWebMvc
@ComponentScan(basePackages = {"com.company.project"})
public class SwaggerConfig
{
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.boot")))
                .apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.cloud")))
                .apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.data.rest.webmvc")))
                .paths(PathSelectors.any())
                .build();
    }
}

<!-- to generate /swagger-ui.html -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.7.0</version>
</dependency>

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.7.0</version>
</dependency>

: , 2.6.0, , Swagger UI 0 api. , , ?

, .

+22
9

, , @EnableSwagger2 Docket Bean.

Docket Bean, , Spring Bean. , docket @Component, , , - , .

+4

, SpringBootApplication - :

@EnableSwagger2
+21

, Spring Security , swagger-ui. , :

  • /swagger-ui.html
  • /Webjars/**
  • /V2/**
  • /-/**

, .

+12

SpringBootServletInitalizer. . , .

public class TestApp extends SpringBootServletInitializer{

    public static void main(String[] args) {

       SpringApplication.run(TestApp.class, args);
   }
}
+3

Spring 2 @SpringBootApplication SpringBootServletInitializer, SpringApplicationBuilder

@SpringBootApplication
public class TestApp extends SpringBootServletInitializer{

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(TestApp.class);
    }


    public static void main(String[] args) {
        SpringApplication.run(TestApp.class, args);
    }
}
+1

Springboot (2.1.2) swagger2 (2.9.2) war tomcat8.5 .

, . AppConfig extends SpringBootServletInitializer

AppConfig

package org.mydomain

import java.net.URL;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;

import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication(scanBasePackages = "org.mydomain")
@EntityScan({"org.mydomain.entity"})
@EnableJpaRepositories({"org.mydomain.repository"})
@EnableSwagger2
@EnableScheduling
public class AppConfig extends SpringBootServletInitializer {

  // We can optionally have spring boot way of starting main method
  public static void main(String[] args) {
     SpringApplication.run(AppConfig.class, args);
  }
}

, Springboot Tomcat

: swagger docket, .

0

.

.

org.liferayasif.documents

org.liferayasif.documents.config

config → .

org.liferayasif.config

org.liferayasif.documents.config

.

0

Spring Security:    void (HttpSecurity http)

.antMatchers("/api/**", "/swagger-ui.html", "/webjars/**", "/v2/**", "/swagger-resources/**").anonymous()

.

0

, :

Spring Security: void configure (HttpSecurity http)

.antMatchers("/api/", "/swagger-ui.html", "/webjars/", "/v2/", "/swagger-resources/").anonymous()

0

Source: https://habr.com/ru/post/1689657/


All Articles