欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringBoot+Maven 多模塊項(xiàng)目的構(gòu)建、運(yùn)行、打包實(shí)戰(zhàn)

 更新時(shí)間:2018年05月24日 14:38:27   作者:zekeTao  
這篇文章主要介紹了SpringBoot+Maven 多模塊項(xiàng)目的構(gòu)建、運(yùn)行、打包實(shí)戰(zhàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

本篇文章主要介紹了SpringBoot+Maven 多模塊項(xiàng)目的構(gòu)建、運(yùn)行、打包,分享給大家,具體如下:

項(xiàng)目使用的工具:

  1. IntelliJ IDEA
  2. JDK 1.8
  3. apache-maven-3.3.9

項(xiàng)目的目錄:

  1. 主項(xiàng)目 springboot-multi
  2. 子模塊 entity、dao、service、web

一、使用IDEA創(chuàng)建一個(gè)SpringBoot項(xiàng)目 : File -> new -> Project 項(xiàng)目名稱為springboot-multi

二、刪除項(xiàng)目中的src目錄,把pom.xml中的項(xiàng)目打包方式改為pom,如下:

<groupId>com.example</groupId> 
<artifactId>springboot-multi</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<!-- 此處改為pom --> 
<packaging>pom</packaging> 

三、創(chuàng)建springboot-multi項(xiàng)目的子模塊,在項(xiàng)目上右鍵單擊,選擇:new -> Module。

四、創(chuàng)建四個(gè)子模塊后,刪除子模塊中 src/main/java、src/main/java下的所有文件(如果沒有文件跳過此操作),只保留web子模塊的SpringBoot的Application主啟動(dòng)類。

五、主項(xiàng)目pom.xml (注意<modules>標(biāo)簽是否指定了子模塊)

<modelVersion>4.0.0</modelVersion>  
  <groupId>com.example</groupId> 
  <artifactId>springboot-multi</artifactId> 
  <version>0.0.1-SNAPSHOT</version> 
  <!-- 此處改為pom --> 
  <packaging>pom</packaging> 
 
  <name>springboot-multi</name> 
  <description>Demo project for Spring Boot</description> 
 
  <modules> 
    <module>web</module> 
    <module>service</module> 
    <module>dao</module> 
    <module>entity</module> 
  </modules> 
 
  <parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.10.RELEASE</version> 
    <relativePath/> <!-- lookup parent from repository --> 
  </parent> 
 
  <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    <java.version>1.8</java.version> 
  </properties> 
 
  <dependencies> 
    <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
  </dependencies> 
 
  <!--指定使用maven打包--> 
  <build> 
    <plugins> 
      <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-compiler-plugin</artifactId> 
        <version>3.1</version> 
        <configuration> 
          <source>${java.version}</source> 
          <target>${java.version}</target> 
        </configuration> 
      </plugin> 
 
      <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <version>2.19.1</version> 
        <configuration> 
          <skipTests>true</skipTests>  <!--默認(rèn)關(guān)掉單元測試 --> 
        </configuration> 
      </plugin> 
    </plugins> 
  </build> 

六、web子模塊pom.xml(依賴service、dao、entity子模塊) 

<modelVersion>4.0.0</modelVersion>  
  <groupId>com.example</groupId> 
  <artifactId>web</artifactId> 
  <version>0.0.1-SNAPSHOT</version> 
  <packaging>jar</packaging> 
 
  <name>web</name> 
  <description>Demo project for Spring Boot</description> 
 
  <parent> 
    <groupId>com.example</groupId> 
    <artifactId>springboot-multi</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <relativePath>../pom.xml</relativePath> 
  </parent> 
 
  <dependencies> 
    <dependency> 
      <groupId>com.example</groupId> 
      <artifactId>service</artifactId> 
      <version>0.0.1-SNAPSHOT</version> 
    </dependency> 
    <dependency> 
      <groupId>com.example</groupId> 
      <artifactId>dao</artifactId> 
      <version>0.0.1-SNAPSHOT</version> 
    </dependency> 
    <dependency> 
      <groupId>com.example</groupId> 
      <artifactId>entity</artifactId> 
      <version>0.0.1-SNAPSHOT</version> 
    </dependency> 
  </dependencies> 
 
  <!--spring boot打包的話需要指定一個(gè)唯一的入門--> 
  <build> 
    <plugins> 
      <plugin> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-maven-plugin</artifactId> 
        <configuration> 
          <!-- 指定該Main Class為全局的唯一入口 --> 
          <mainClass>com.example.WebApplication</mainClass> 
          <layout>ZIP</layout> 
        </configuration> 
        <executions> 
          <execution> 
            <goals> 
              <goal>repackage</goal><!--可以把依賴的包都打包到生成的Jar包中--> 
            </goals> 
          </execution> 
        </executions> 
      </plugin> 
    </plugins> 
  </build> 

七、service子模塊pom.xml(依賴 dao 、entity子模塊)

<modelVersion>4.0.0</modelVersion> 
 
  <groupId>com.example</groupId> 
  <artifactId>service</artifactId> 
  <version>0.0.1-SNAPSHOT</version> 
  <packaging>jar</packaging> 
 
  <name>service</name> 
  <description>Demo project for Spring Boot</description> 
 
  <parent> 
    <groupId>com.example</groupId> 
    <artifactId>springboot-multi</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <relativePath>../pom.xml</relativePath> 
  </parent> 
 
  <dependencies> 
    <dependency> 
      <groupId>com.example</groupId> 
      <artifactId>dao</artifactId> 
      <version>0.0.1-SNAPSHOT</version> 
    </dependency> 
    <dependency> 
      <groupId>com.example</groupId> 
      <artifactId>entity</artifactId> 
      <version>0.0.1-SNAPSHOT</version> 
    </dependency> 
  </dependencies> 

八、dao子模塊pom.xml (依賴entity子模塊) 

<modelVersion>4.0.0</modelVersion> 
 
<groupId>com.example</groupId> 
<artifactId>dao</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>jar</packaging> 
 
<name>dao</name> 
<description>Demo project for Spring Boot</description> 
 
<parent> 
  <groupId>com.example</groupId> 
  <artifactId>springboot-multi</artifactId> 
  <version>0.0.1-SNAPSHOT</version> 
  <relativePath>../pom.xml</relativePath> 
</parent> 
 
<dependencies> 
  <dependency> 
    <groupId>com.example</groupId> 
    <artifactId>entity</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
  </dependency> 
</dependencies> 

九、entity子模塊

<modelVersion>4.0.0</modelVersion> 
 
<groupId>com.example</groupId> 
<artifactId>entity</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>jar</packaging> 
 
<name>entity</name> 
<description>Demo project for Spring Boot</description> 
 
  <parent> 
    <groupId>com.example</groupId> 
    <artifactId>springboot-multi</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <relativePath>../pom.xml</relativePath> 
  </parent> 

十、pom.xml文件中需要注意的就是:

  1. 主項(xiàng)目的modules標(biāo)簽指定的子模塊是否正確
  2. 子模塊之間的依賴
  3. 子模塊的parent標(biāo)簽

十一、web子模塊的Application啟動(dòng)類:

@RestController 
@SpringBootApplication 
public class WebApplication { 
 
  public static void main(String[] args) { 
    SpringApplication.run(WebApplication.class, args); 
  } 
 
  @RequestMapping(value = "/test",method = RequestMethod.GET) 
  public String test(){ 
    return "test success"; 
  } 
} 

十二、執(zhí)行main方法啟動(dòng)項(xiàng)目,訪問localhost:8080/test,出現(xiàn)如下頁面表示項(xiàng)目搭建成功:

十三、項(xiàng)目打包命令: mvn clean package 或者 使用右邊工具欄的圖形化界面打包也可以:

十四、打包成功日志:

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論