阿里雲快速搭建springboot+maven父子專案
阿新 • • 發佈:2020-07-22
1.準備:
2018.2 版本以上的 idea
jdk:1.8
maven: idea 自帶(配置檔案,我是連線的阿里的)
阿里雲連線:https://start.aliyun.com/
2.建立父類專案:
2.1 使用阿里雲連線:https://start.aliyun.com/(https://start.spring.io 這個網站是國外的,經常連線超時)
2.2 父類專案基本資訊
2.3 初始化 依賴包
2.4 父類專案名及路徑
2.5 生成專案後生成的目錄
2.6 檢視maven 是否下載好依賴
3. 建立子專案:
3.1.。。。
3.2.。。。
3.3.。。。
3.4.。。。
3.5.。。。
3.6.。。。如果發現子專案沒有在maven目錄中,請點選下圖左上角 :圈圈
4.修改pom.xml 檔案
4.1 在父專案 pom.xml 檔案中
新增:
<packaging>pom</packaging> <modules> <module>springboot-hello</module> </modules>
<?xml version="1.0" encoding="UTF-8"?> <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>springboot-demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>springboot-demo</name> <description>Demo project for Spring Boot</description> <packaging>pom</packaging> <modules> <module>springboot-hello</module> </modules> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <spring-boot.version>2.3.0.RELEASE</spring-boot.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
4.1 在子專案 pom.xml 檔案中
新增:
<parent> <groupId>com.example</groupId> <artifactId>springboot-demo</artifactId> <version>0.0.1-SNAPSHOT</version> </parent>
<?xml version="1.0" encoding="UTF-8"?> <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.example</groupId> <artifactId>springboot-demo</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>com.example</groupId> <artifactId>springboot-hello</artifactId> <version>0.0.1-SNAPSHOT</version> <name>springboot-hello</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <spring-boot.version>2.3.0.RELEASE</spring-boot.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
5. 上面已將父子專案建立好了,並配置了pom.xml 檔案 現在使用maven中的:clean,compile 測試一下
5.1 在父maven 專案中點選 clean
5.1 在父maven 專案中點選 compile
6. 快建springboot專案時生成了好多配置檔案,如果你喜歡乾淨,那你就可以將其刪掉,父專案中的src檔案也沒有用,一塊也刪除