【问题标题】:Java Spring @GetMapping not found未找到 Java Spring @GetMapping
【发布时间】:2020-03-31 02:42:52
【问题描述】:

I write two functions @GetMapping in one class. Function getProcessImage is working but Function hello is not working.

NOT FOUND 404

我在一个类中编写了两个函数@GetMapping。函数 getProcessImage 正在工作,但函数 hello 不工作。找不到 404。

@GetMapping(value = "/{processInsID}/{containerId}")
public ServiceResponse<String> getProcessImage(@PathVariable("processInsID") long procInstId,
                                               @PathVariable("containerId") String containerId) {
    AuthenticationInfo bpmAuthenInfo = new AuthenticationInfo(env.getProperty("jbpm.url"),
            env.getProperty("jbpm.username"), env.getProperty("jbpm.password"), "");
    String result = jbpmService.getImageProcessInProgess(bpmAuthenInfo, containerId, procInstId);
    try {
        return new ServiceResponse<String>(Constant.ServiceResponse.CODE_SUCCESS,
                Constant.ServiceResponse.MSG_SUCCESS, result);
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
        return new ServiceResponse<String>(Constant.ServiceResponse.CODE_ERROR, e.getMessage(), null);
    }
}

@GetMapping(value = "/image/")
public ServiceResponse<String> hello() {
    return new ServiceResponse<String>(Constant.ServiceResponse.CODE_ERROR,"okok", null);
}

【问题讨论】:

  • 请添加控制器代码以了解您的问题
  • getProcessImage() 工作正常,但找不到 hello() :(
  • 您在浏览器中的 hello URL 应该是“/image/”,而不是带有斜杠的“/image”
  • getProcessImage() url 映射可能会导致 hello() 出现问题并添加完整的控制器类

标签: java spring spring-boot rest


【解决方案1】:

您需要将 getMapping 更改为 /image(即删除 / ),或者您需要在 url 路径中添加 image/。我建议您在代码中将 / 删除为 /image

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-13
    • 2020-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-25
    • 1970-01-01
    相关资源
    最近更新 更多