1. 程式人生 > >maven聚合專案搭建,簡單的SpringBoot整合

maven聚合專案搭建,簡單的SpringBoot整合

1、new Maven project ,第一行 create a .... 打鉤



2、專案結構如下圖,可以刪除src,只保留pom


3、右鍵該專案,new   project  選擇maven model  點選next,填寫model 那麼,比如我的 填的是 songsir-web,因為該model我作為應用檢視層,專案中的 頁面和 controller都包含在改model下,所以next,選擇如下圖,然後,next finish。


4、接著在新建 model,分別為songsir-service,songsir-bean,songsir-dao,songsir-common,全部選擇:


新建完成,目錄結構如下:


5、接著,配置各個模組之間的依賴關係。我的依賴關係是:web依賴於service,service依賴於bean,bean依賴於dao,dao依賴於common,所以依賴傳遞為  web<--service<--bean<--dao<--common

首先在songsir-web下的pom裡面新增songsir-service的依賴


同理,在service,bean,dao分別新增下層的依賴。

6、新增完之後,右鍵 專案,run as  maven install,完成之後,檢視songsir-web下,發現,其他模組的依賴都已經引入


至此,maven聚合專案搭建完成,下面引入Springboot依賴即可搭建簡單的SpringBoot專案。

7、在專案跟目錄下pom中新增

        <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>

<relativePath />

</parent>


接著,在songsir-common下的pom裡新增

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

</dependency>


儲存,依賴自動下載,引入。然後發現songsir-web下jar包都已經被引入


8、在sognsir-web下面建立啟動類  MyApplication.java。


然後,在com.songsir的下一層包(必須是下一層),建立個普通controller作為測試。


9、run  MyApplication這個類,如下表示啟動成功。


然後,在瀏覽器訪問:localhost:8080/helloWorld


10、over。