您好,登錄后才能下訂單哦!
Eclipse創(chuàng)建Springboot聚合項(xiàng)目
1.1 創(chuàng)建一個(gè)Maven工程
1.2 創(chuàng)建一個(gè)簡(jiǎn)單的項(xiàng)目
1.3 填寫項(xiàng)目基本信息
1.4 項(xiàng)目目錄結(jié)構(gòu)
1.5 編寫父項(xiàng)目pom.xml文件信息
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- 項(xiàng)目說明:這里作為聚合工程的父工程 -->
<modelVersion>4.0.0</modelVersion>
<groupId>com.qfx</groupId>
<artifactId>parenteProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parenteProject</name>
<description>這是一個(gè)Maven聚合項(xiàng)目的父項(xiàng)目</description>
<!-- 設(shè)置父類,整合第三方常用框架依賴信息(各種依賴信息),這里繼承SpringBoot提供的父工程 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<!-- 設(shè)置公共參數(shù) -->
<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>
<!-- 1.引入springboot核心包,整合SpringMVC Web組件 -->
<!-- 實(shí)現(xiàn)原理:Maven依賴?yán)^承關(guān)系,相當(dāng)于把第三方常用Maven依賴信息,在parent項(xiàng)目中已經(jīng)封裝好了 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 2. 引入springboot測(cè)試包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 3. springboot外部tomcat支持,用于編譯jsp -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- 4. 打war包時(shí)加入此項(xiàng), 告訴spring-boot tomcat相關(guān)jar包用外部的,不要打進(jìn)去 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests><!--默認(rèn)關(guān)掉單元測(cè)試 -->
</configuration>
</plugin>
</plugins>
</build>
</project>
2.1 創(chuàng)建一個(gè)Maven子工程
2.2 填寫子項(xiàng)目名稱
2.3 選擇子項(xiàng)目原型
2.4 填寫基本信息
2.5 項(xiàng)目目錄結(jié)構(gòu)
注意:如果子項(xiàng)目與父項(xiàng)目平級(jí)顯示的話,可以進(jìn)行如下操作,切換操作視圖即可
2.6 父項(xiàng)目的pom.xml文件已經(jīng)引用了子項(xiàng)目,如圖:
2.7 編寫子項(xiàng)目pom.xml文件信息
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- 項(xiàng)目說明:這里作為聚合工程的子工程 -->
<modelVersion>4.0.0</modelVersion>
<artifactId>project-web</artifactId>
<name>project-web</name>
<!-- 打包方式為war,默認(rèn)不寫為jar -->
<packaging>war</packaging>
<!-- 設(shè)置父類,,這里繼承parenteProject父工程 -->
<parent>
<groupId>com.qfx</groupId>
<artifactId>parenteProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
</project>
2.8 修改Spingboot子項(xiàng)目的啟動(dòng)類org.project.web.App.java
package org.project.web;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
2.9 添加一個(gè)測(cè)試類org.project.web.controller.TestController.java
package org.project.web.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("test")
public class TestController {
@RequestMapping("sayHello")
public String sayHello() {
return "你好呀~!";
}
}
2.10 啟動(dòng)Springboot
2.11 測(cè)試,http://127.0.0.1:8080/test/sayHello
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。