首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >API (Spring SwaggerHub生成)结果为404,尽管映射正确。

API (Spring SwaggerHub生成)结果为404,尽管映射正确。
EN

Stack Overflow用户
提问于 2020-10-05 11:12:03
回答 1查看 307关注 0票数 0

我最近使用了SwaggerHub,并试图在生成的Spring中将Spring版本(1.5.22.RELEASE )升级到2.3.3.RELEASE,原因是访问管理(凯克雅克)。

将spring引导版本升级到2.0.1,results确实使用Keycloak修复了问题,但是会导致api的每个路径都出现404错误。总之,没有路径可以访问,尽管是根据日志映射。

版本的问题:

1.5.22.RELEASE: API-路径可以访问-获取NoClassDefFoundError: WebServerFactoryCustomizer

2.0.0.RELEASE-2.0.9 Keycloak :Keycloak:API-路径正在映射,但没有访问-启动时没有的错误。

2.1.0.RELEASE-2.3.3. Keycloak :Keycloak:API-路径不会被映射-在启动时没有发生的错误。

这是使用2.0.1.RELEASE的日志的一部分:

代码语言:javascript
复制
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 -接口:

代码语言:javascript
复制
/**
 * 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 -控制器:

代码语言:javascript
复制
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):样式,以获得更好的概述。

EN

回答 1

Stack Overflow用户

发布于 2020-10-06 07:31:00

尝试访问使用1.5.33.RELEASE版本的localhost:8080/TEST/API/1.0.0/getMyConfigurations上的路径。

在高于server.contextPath的版本中,似乎忽略了application.properties上的2.x.x.RELEASE属性,因此必须在没有server.contextPath的情况下调用路径(localhost:8080/getMyConfigurations)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64207494

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档