I can't log in to swagger. Unable to infer base url

69 Views Asked by At

Gives the following error. I don't use spring Security tried different versions, rebuilt the project, no idea what the problem is

@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.mycompany.trainbooking.controller"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo())
                .host("localhost:8080")
                .pathMapping("/tickets");
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Train Booking API")
                .description("API для управления бронированием билетов на поезд")
                .version("1.0")
                .build();
    }
}


<properties>
        <java.version>17</java.version>
    </properties>
<artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.4</version>
<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.10.5</version> <!-- Обновите до актуальной версии Swagger -->
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.10.5</version> <!-- Используйте ту же версию, что и springfox-swagger2 -->
        </dependency>
@RestController
@RequestMapping("/tickets")

enter image description here

I wrote path Mapping("/") differently, and generally cleaned

1

There are 1 best solutions below

0
sleepyhead On

When I look at the sources below I see a project that looks abandoned for 3 years now, right after 3.0.0 was released, with questions on this error not answered. My guess is that setting the baseUrl is required somewhere and I would experiment with the @enableswagger2 or use spring boot without springfox.

https://github.com/springfox/springfox

springfox-boot-starter 3.0.0 : Unable to infer base url

https://springfox.github.io/springfox/docs/current/

https://github.com/springfox/springfox/issues/4064

@EnableSwagger2

public SwaggerUiWebMvcConfigurer(String baseUrl) {
    this.baseUrl = baseUrl;
  }