您的位置:首页 > 汽车 > 新车 > 网站开发制作公司排行_免费主机免费域名_网络工程师培训一般多少钱_太原最新情况

网站开发制作公司排行_免费主机免费域名_网络工程师培训一般多少钱_太原最新情况

2025/6/19 10:43:20 来源:https://blog.csdn.net/qq_42810926/article/details/146351944  浏览:    关键词:网站开发制作公司排行_免费主机免费域名_网络工程师培训一般多少钱_太原最新情况
网站开发制作公司排行_免费主机免费域名_网络工程师培训一般多少钱_太原最新情况

一、创建一个父模块

不需要添加什么springweb,创建好之后是这样子的,有这些文件

在这里插入图片描述

删掉 .mvn,src,HELP.md,mvnw,mvnw.cmd

在这里插入图片描述

最原始的pom.xml

<?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>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.4.3</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>org.example</groupId><artifactId>owntestdemo</artifactId><version>0.0.1-SNAPSHOT</version><name>owntestdemo</name><description>owntestdemo</description><url/><licenses><license/></licenses><developers><developer/></developers><scm><connection/><developerConnection/><tag/><url/></scm><properties><java.version>21</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

打开pom.xml,需要删掉<build>标签下面的

    <build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>

删掉<parent>标签

    <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.4.3</version><relativePath/> <!-- lookup parent from repository --></parent>

删掉<name>和<description>标签

    <name>owntestdemo</name><description>owntestdemo</description>

删除<dependencies>标签

    <dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>

标签<dependencyManagement>来管理依赖

    <dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version></dependency></dependencies></dependencyManagement>

在<properties>中添加<spring-boot.version>

<spring-boot.version>3.4.3</spring-boot.version>

添加<packaging>,因为外层只是管理依赖的一个文件

<packaging>pom</packaging>

添加<build>标签

    <build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>${maven.compiler.source}</source><target>${maven.compiler.target}</target><encoding>${project.build.sourceEncoding}</encoding></configuration></plugin></plugins><pluginManagement><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugine</artifactId><version>${spring.boot.version}</version><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></pluginManagement></build>

在<properties>里面添加<maven.compiler.source>、<maven.compiler.source>、<maven.compiler.source>

    <properties><maven.compiler.source>17</maven.compiler.source><maven.compiler.source>17</maven.compiler.target><maven.compiler.source>UTF-8</project.build.sourceEncoding></properties>

最后pom.xml的样子

<?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>org.example</groupId><artifactId>owntestdemo</artifactId><version>0.0.1-SNAPSHOT</version><packaging>pom</packaging><url/><licenses><license/></licenses><developers><developer/></developers><scm><connection/><developerConnection/><tag/><url/></scm><properties><maven.compiler.source>17</maven.compiler.source><maven.compiler.target>17</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><java.version>21</java.version><spring-boot.version>3.4.3</spring-boot.version></properties><dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>${maven.compiler.source}</source><target>${maven.compiler.target}</target><encoding>${project.build.sourceEncoding}</encoding></configuration></plugin></plugins><pluginManagement><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugine</artifactId><version>${spring.boot.version}</version><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></pluginManagement></build></project>

二、创建子模块

右击owntestdemo项目文件夹 --> New --> Module

在这里插入图片描述

选择Spring Boot,创建module-common

在这里插入图片描述

点next,spring不用管,也不需要勾选任何springweb等

在这里插入图片描述

删掉 .mvn,.gitignore,HELP.md,mvnw,mvnw.cmd

删除后

在这里插入图片描述

module-common原pom.xml

<?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>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.4.3</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>org.example</groupId><artifactId>module-common</artifactId><version>0.0.1-SNAPSHOT</version><name>module-common</name><description>module-common</description><url/><licenses><license/></licenses><developers><developer/></developers><scm><connection/><developerConnection/><tag/><url/></scm><properties><java.version>21</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

修改<parent>标签中的<groupId>标签

	<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.4.3</version><relativePath/> <!-- lookup parent from repository --></parent>

把子类pom.xml中<parent>标签里面的数值改成父类<project>标签里面的数值

    <groupId>org.example</groupId><artifactId>owntestdemo</artifactId><version>0.0.1-SNAPSHOT</version><packaging>pom</packaging>

子类module-common的pom.xml修改后

	<parent><groupId>org.example</groupId><artifactId>owntestdemo</artifactId><version>0.0.1-SNAPSHOT</version><relativePath/> <!-- lookup parent from repository --></parent>

删除module-common中pom.xml里的<name>标签和<description>标签

原:

	<groupId>org.example</groupId><artifactId>module-common</artifactId><version>0.0.1-SNAPSHOT</version><name>module-common</name><description>module-common</description>

改后:

	<groupId>org.example</groupId><artifactId>module-common</artifactId><version>0.0.1-SNAPSHOT</version>

删除<build>标签

	<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>

删除<dependencies>标签里面的<dependency>标签

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

在父模块pom.xml中<project>标签下,也就是和<build>等标签同级,添加<modules>标签内容,这个就是模块管理子模块。

    <modules><module>module-common</module></modules>

子模块<dependencies>标签添加<dependency>标签,这个是springweb依赖

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

修改module-common中pom.xml的<parent>标签中的<relativePath>标签,如下

原:

<relativePath/>

改后:

    <parent><groupId>org.example</groupId><artifactId>owntestdemo</artifactId><version>0.0.1-SNAPSHOT</version><relativePath>../pom.xml</relativePath> <!-- lookup parent from repository --></parent>

修改<groupId>标签

原:

    <groupId>org.example</groupId>

改后:

    <groupId>org.example.common</groupId><artifactId>module-common</artifactId><version>0.0.1-SNAPSHOT</version>

需要把父模块中的pom.xml中的<dependencyManagement>标签,添加<type>和<scope>标签。指定类型不然就会有问题。

    <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>

加了<type>和<scope>标签子模块的pom.xml就会出现这个向上的箭头

在这里插入图片描述

如果不加<type>和<scope>标签子模块的pom.xml就不会出现这个向上的箭头,就会有问题。

在子模块pom.xml中添加 spring-boot-starter-test 依赖

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

最后

owntestdemo父模块的pom.xml

<?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>org.example</groupId><artifactId>owntestdemo</artifactId><version>0.0.1-SNAPSHOT</version><packaging>pom</packaging><url/><licenses><license/></licenses><developers><developer/></developers><scm><connection/><developerConnection/><tag/><url/></scm><properties><maven.compiler.source>17</maven.compiler.source><maven.compiler.target>17</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><java.version>21</java.version><spring-boot.version>3.4.3</spring-boot.version></properties><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>${maven.compiler.source}</source><target>${maven.compiler.target}</target><encoding>${project.build.sourceEncoding}</encoding></configuration></plugin></plugins><pluginManagement><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugine</artifactId><version>${spring.boot.version}</version><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></pluginManagement></build><modules><module>module-common</module></modules></project>

module-common 子模块的pom.xml

<?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>org.example</groupId><artifactId>owntestdemo</artifactId><version>0.0.1-SNAPSHOT</version><relativePath>../pom.xml</relativePath> <!-- lookup parent from repository --></parent><groupId>org.example.common</groupId><artifactId>module-common</artifactId><version>0.0.1-SNAPSHOT</version><url/><licenses><license/></licenses><developers><developer/></developers><scm><connection/><developerConnection/><tag/><url/></scm><properties><java.version>21</java.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></dependency></dependencies></project>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com