创建父项目
File---new---project:
填写项目信息
默认即可,点击finish创建完成:
由于父项目只用到pom文件 所以把src删掉即可:
父项目pom文件:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.appst</groupId> <artifactId>mhd-cloud-parent</artifactId> <version>1.0-SNAPSHOT</version> <!--springboot 版本--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.3.RELEASE</version> </parent> <!--子项目module--> <modules> <module>mhd-cloud-eureka</module> </modules> <!--常规属性设置--> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <!-- SpringCloud 版本--> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Hoxton SR8</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <!--springboot 各种环境的依赖--> <dependencies> <!--端点依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!--热部署依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> </dependencies> <!--maven插件 便于打包--> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
pom文件说明:
引入springboot【版本:2.3.3】
<!--springboot 版本--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.3.RELEASE</version> </parent>
引入springcloud【版本:Hoxton SR8】
<!-- SpringCloud 版本--> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Hoxton.SR8</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
子项目引入:
<modules> <module>mhb-cloud-eureka</module> </modules>
springboot环境依赖【子项目可继承】:
<!--springboot 各种环境的依赖--> <dependencies> <!--端点依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!--热部署依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> </dependencies>
maven打包插件:
<!--maven插件 便于打包--> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
springboot和springcloud版本对应
spring-cloud-dependencies的maven地址:https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies
spring-boot-starter-parent的maven地址:https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent
导jar包时需注意,springcloud和springboot有对应版本号,否则会无法启动。
创建子项目
父项目---new---Module:
选择创建Spring项目:
填写项目基本信息:
选择版本和web依赖插件:
创建完成:
子项目pom文件:--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> <!--父类为mhb-cloud-parnet项目--> <parent> <groupId>com.appst</groupId> <artifactId>mhd-cloud-parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>com.appst</groupId> <artifactId>mhd-cloud-eureka</artifactId> <version>0.0.1-SNAPSHOT</version> <name>mhd-cloud-eureka</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <!--本项目依赖的各种环境--> <dependencies> <!--web环境支持--> <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> </dependency> <!--eureka服务环境支持--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <!--eureka服务安全控制--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
父项目pom文件:--添加module
<modules> <module>mhd-cloud-eureka</module> </modules>