繁体   English   中英

如何使用 spring 引导应用程序在同一应用程序中使用 rest api 来自同一应用程序中的另一个模块的一个模块

[英]how can I consume rest api of one module from other module in same application using spring boot application without module dependency

我在多模块项目中工作。 目前我面临以下问题:

  • 模块 A

  • 模块 B

  • 模块 A 依赖于 B

  • 模块 A 具有以下方法 @GetMapping(path = "/getworkspaces")

     public Map<String, Object> getWorkSpaces()) { Map<String, Object> workspaces = null; workspaces = this.dataSetService.getWorkSpaces(); return workspaces;

    }

  • 模块 B 具有以下方法,我需要使用模块 A 提到的端点

    公共字符串consumeModuelAMethod(){

     RestTemplate restTemplate = new RestTemplate(); String url = "http://localhost:8080/getworkspaces" try { ResponseEntity<String> responseMap = restTemplate.getForEntity(url, String.class); if (HttpStatus.OK.equals(responseMap.getStatusCode())){ return responseMap.getBody(); }else { return null; } } catch (RestClientException ex){ex.printStackTrace();}}
  • 当我通过模块 A 中的 RestTemplate 调用“http://localhost:8080/getworkspaces”时。

  • 它给我 404(未找到)

  • 我正在使用安全的 api 机制意味着 SSO。 那么如何在没有任何依赖关系的情况下在同一项目的另一个模块中调用一个模块的 api。

  • 任何帮助将不胜感激

我已经在 header 授权中设置了访问令牌及其对我的工作。 ——法祖尔·拉赫曼

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM