如何使SpringBoot做爲Maven構建的項目的一個子模塊

1.問題

通常使用springboot都會引用springboot做爲parent,在實際項目中web只是系統模塊的一個子集。固然你能夠作兩個項目來管理,一個項目用來作各類支持包,一個項目專門作web,可是這樣不只調試不方便並且將面臨更多的隱患,好比發佈前的版本控制問題等。
因此最優方案已定是將Springboot做爲一個Maven項目的子模塊來處理。web

2.先改一下咱們項目的pom.xml

也就是在咱們項目的pom中,也就是其餘子項目的parent中增長所有的sprintboot的引用。注意一下這段是整段新增的。spring

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-dependencies</artifactId>
      <version>2.0.1.RELEASE</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

3.在web子模塊中增長springboot引用

在咱們子模塊的pom中像使用其餘包同樣加入springboot,注意dependencies多是原有的,你只要增長dependency部分便可。
若是是一個空項目能夠像下面這樣引用。tomcat

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

4.須要一個server來啓動web

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class clientServer {
    public static void main(String[] args) {
        SpringApplication.run(clientServer.class, args);
    }
}

5.以後就正常愉快的使用內置的tomcat和地址路由吧

相關文章
相關標籤/搜索