API (Spring Boot - SwaggerHub Generated) дает результат 404, несмотря на то, что он правильно сопоставлен

Недавно я использовал SwaggerHub и попытался обновить версию Spring-boot (1.5.22.RELEASE до 2.3.3.RELEASE) в сгенерированном Spring-Boot api из-за управления доступом (Keycloak).

Обновление версии spring -boot до 2.0.1.RELEASE устраняет проблемы с использованием Keycloak, однако приводит к ошибке 404 для каждого пути api. В общем, доступ к пути невозможен, несмотря на то, что он отображается в соответствии с журналом.

Проблемы с версиями:

1.5.22.RELEASE: API-путь доступен - получение NoClassDefFoundError: WebServerFactoryCustomizer

2.0.0.RELEASE - 2.0.9.RELEASE: пути API отображаются, но нет доступа - нет ошибки с Keycloak при запуске.

2.1.0.RELEASE - 2.3.3.RELEASE: Пути API не сопоставляются - нет ошибки с Keycloak при запуске.

Это раздел журнала, использующий 2.0.1.RELEASE:

2020-10-05 10:46:47.012  INFO 25040 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/getIcnByNumber],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<java.util.List<io.swagger.model.ModelConfiguration>> io.swagger.api.GetIcnByNumberApiController.getIcnByNumber()
2020-10-05 10:46:47.015  INFO 25040 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/getMyConfigurations],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<java.util.List<io.swagger.model.ModelConfiguration>> io.swagger.api.GetMyConfigurationsApiController.callConfiguration()
2020-10-05 10:46:47.017  INFO 25040 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/getMyProjects],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<java.util.List<io.swagger.model.ProjectModel>> io.swagger.api.GetMyProjectsApiController.getMyProjectsGet()
2020-10-05 10:46:47.020  INFO 25040 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/getProjectConfiguration/{projectId}],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<io.swagger.model.ProjectConfiguration> io.swagger.api.GetProjectConfigurationApiController.getProjectConfigurationProjectIdGet(java.lang.String)
2020-10-05 10:46:47.021  INFO 25040 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/getRequestOverview],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<java.util.List<io.swagger.model.RequestOverview>> io.swagger.api.GetRequestOverviewApiController.getRequestOverview()

Пример кода:

/ getMyConfigurations - Интерфейс:

/**
 * NOTE: This class is auto generated by the swagger code generator program (3.0.21).
 * https://github.com/swagger-api/swagger-codegen
 * Do not edit the class manually.
 */
package io.swagger.api;

import io.swagger.model.ModelConfiguration;
import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.CookieValue;

import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;
import java.util.Map;
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2020-09-14T09:55:45.552Z[GMT]")
@Api(value = "getMyConfigurations", description = "the getMyConfigurations API")
public interface GetMyConfigurationsApi {

    @ApiOperation(value = "searches inventory", nickname = "callConfiguration", notes = "By passing in the appropriate options, you can search for available inventory in the system ", response = ModelConfiguration.class, responseContainer = "List", tags={ "developers", })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "search results matching criteria", response = ModelConfiguration.class, responseContainer = "List"),
        @ApiResponse(code = 400, message = "bad input parameter") })
    @RequestMapping(value = "/getMyConfigurations",
        produces = { "application/json" }, 
        method = RequestMethod.GET)
    ResponseEntity<List<ModelConfiguration>> callConfiguration();

}

/ getMyConfigurations - Контроллер:

package io.swagger.api;

import io.swagger.model.ModelConfiguration;
import io.swagger.model.Originator;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.*;
import javax.validation.Valid;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2020-08-28T09:14:46.542Z[GMT]")
@Controller
public class GetMyConfigurationsApiController implements GetMyConfigurationsApi {

    private static final Logger log = LoggerFactory.getLogger(GetMyConfigurationsApiController.class);

    private final ObjectMapper objectMapper;

    private final HttpServletRequest request;

    @org.springframework.beans.factory.annotation.Autowired
    public GetMyConfigurationsApiController(ObjectMapper objectMapper, HttpServletRequest request) {
        this.objectMapper = objectMapper;
        this.request = request;
    }

    public ResponseEntity<List<ModelConfiguration>> callConfiguration() {
        ArrayList<ModelConfiguration> mcList = new ArrayList<>();
        
        
        return new ResponseEntity<List<ModelConfiguration>>(mcList,HttpStatus.OK);
    }
}

РЕДАКТИРОВАТЬ (05.10.2020): стили для лучшего обзора.


person Sercan Samet Savran    schedule 05.10.2020    source источник


Ответы (1)


Пытался получить доступ к пути на localhost: 8080 / TEST / API / 1.0.0 / getMyConfigurations, который работал с версией 1.5.33.RELEASE.

Похоже, что атрибут server.contextPath в application.properties игнорируется в версиях выше 2.x.x.RELEASE. Оказалось, что путь нужно вызывать без server.contextPath (localhost: 8080 / getMyConfigurations).

person Sercan Samet Savran    schedule 06.10.2020
comment
Он игнорируется, потому что свойство было перемещено. См. stackoverflow.com/a/47535311/5474918 - person martinspielmann; 06.10.2020