1.問題
一般使用springboot都會引用springboot作為parent,在實際項目中web只是系統模塊的一個子集。當然你可以做兩個項目來管理,一個項目用來做各種支持包,一個項目專門做web,但是這樣不僅調試不方便而且將面臨更多的隱患,比如發布前的版本控制問題等。
所以最優方案已定是將Springboot作為一個Maven項目的子模塊來處理。
2.先改一下我們項目的pom.xml
也就是在我們項目的pom中,也就是其他子項目的parent中增加全部的sprintboot的引用。注意一下這段是整段新增的。
<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部分即可。
如果是一個空項目可以像下面這樣引用。
<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);
}
}