Java 如何使用SpringBoot应用程序从同一应用程序中的另一个模块使用一个模块的RESTAPI,而不依赖于模块
我在多模块项目中工作。目前我面临以下问题:Java 如何使用SpringBoot应用程序从同一应用程序中的另一个模块使用一个模块的RESTAPI,而不依赖于模块,java,spring-boot,Java,Spring Boot,我在多模块项目中工作。目前我面临以下问题: 模块A 模块B 模块A依赖于模块B 模块A具有以下方法 @GetMapping(路径=“/GetWorkspace”) publicmap getworkspace()){ 映射工作空间=空; 工作空间=this.dataSetService.getworkspace(); 返回工作区; } 模块B有以下方法,其中我需要使用前面提到的端点模块A 公共字符串ConsumerModueLaMethod() { RestTemplate Rest
- 模块A
- 模块B
- 模块A依赖于模块B
- 模块A具有以下方法
@GetMapping(路径=“/GetWorkspace”)
}publicmap getworkspace()){ 映射工作空间=空; 工作空间=this.dataSetService.getworkspace(); 返回工作区;
- 模块B有以下方法,其中我需要使用前面提到的端点模块A
公共字符串ConsumerModueLaMethod()
{
RestTemplate RestTemplate=new RestTemplate(); 字符串url=”http://localhost:8080/getworkspaces" 试一试{ ResponseEntity responseMap=restTemplate.getForEntity(url,String.class); if(HttpStatus.OK.equals(responseMap.getStatusCode())){ 返回responseMap.getBody(); }否则{ 返回null; } }catch(RestClientException ex){ex.printStackTrace();}
- 当我打电话时“http://localhost:8080/getworkspaces“通过模块A中的RestTemplate
- 它给我404(未找到)
- 我使用的安全api机制意味着SSO。那么,如何在同一项目的另一个模块中调用一个模块的api,而不存在任何依赖关系呢
- 任何帮助都将不胜感激
public Map<String, Object> getWorkSpaces()) {
Map<String, Object> workspaces = null;
workspaces = this.dataSetService.getWorkSpaces();
return workspaces;
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();}}