简体   繁体   English

Spring Boot Maven MultiModule Rest API调用

[英]Spring boot Maven MultiModule Rest api Call


All I'm new on Spring boot and have a question. 我在Spring Boot上是新手,有一个问题。 Currently I'm working with the spring boot multi module project. 目前,我正在从事Spring Boot多模块项目。 I have 3 spring boot project. 我有3个Spring Boot项目。
like A,B,C, each have rest-controller like below:- 像A,B,C一样,每个都有如下的休息控制器:
--------------------Project-A---------------------------------- -------------------- Project-A --------------------------- -------

@RequestMapping(value = "/demoa")
public String demoa() {
    return "demoa";
}

--------------------Project-B---------------------------------- -------------------- Project-B --------------------------- -------

@RequestMapping(value = "/demob")
public String demob() {
    return "demob";
}

--------------------Project-C---------------------------------- -------------------- Project-C --------------------------- -------

@RequestMapping(value = "/democ")
public String democ() {
    return "democ";
}

I add the both (B, C) project as a mavend dependency in Project(A) and compiled all 我将两个(B,C)项目都添加为Project(A)中的Mavend依赖项,并编译了所有

<dependency>
    <groupId>com.b</groupId>
    <artifactId>demob</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
    <groupId>com.c</groupId>
    <artifactId>democ</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

after that i run my project like "mvn Spring-boot run" it run on 8080. When i call the "Rest /demoa" it give me the response while when i try to call other rest it show these error below: 之后,我像“ mvn Spring-boot run”一样运行我的项目,它在8080上运行。当我调用“ Rest / demoa”时,它给了我响应,而当我尝试调用其他其余代码时,它显示以下错误:

{
    "timestamp": "2018-04-25T14:47:56.816+0000",
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/demob"
}

My Question is how I get the response of both 2 api while running the project"A" 我的问题是在运行项目“ A”时如何获得两个API的响应

You need to make sure that your controllers in Project A and Project B are scanned and autoconfigured. 您需要确保已对Project AProject B中的控制器进行了扫描和自动配置。 What you need to do is to use the @ComponentScan annotation in your main class and give it packages on Components and Controllers in the Project A and Project B 您需要做的是在主类中使用@ComponentScan批注,并在Project AProject B中的组件和控制器上给它提供程序包。

For /demob and /democ . 对于/demob/democ You need to run the corresponding projects or: 您需要运行相应的项目或:

You can: 您可以:

  • deploy all projects in your single tomcat server. 在单个tomcat服务器中部署所有项目。
  • Deploy a load balancer from your hosting provider, or you can use Nginx for doing that. 从托管服务提供商部署负载平衡器,也可以使用Nginx进行此操作。
  • Have three tomcat servers. 有三个tomcat服务器。
  • Have single spring boot project but three Rest controllers. 具有单个spring boot项目,但具有三个Rest控制器。

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

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