Maven搭建springboot Maven搭建springboot项目的方法步骤
哈工大的许政 人气:0Maven搭建springboot项目
本文是基于Windows 10系统环境,使用Maven搭建springboot项目
- Windows 10
- apache-maven-3.6.0
- IntelliJ IDEA 2018.3.4 x64
一、springboot项目搭建
(1) 新建目录
在某个可用目录下,新建一个文件夹,本文新建目录为 D:\demo\zs200
(2) 创建maven父工程zs200a-parent
填写项目maven坐标
填写项目名称和路径
(2) maven父工程zs200a-parent的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.chaoyue.zs200a</groupId> <artifactId>zs200a-parent</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.6.RELEASE</version> <relativePath/> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-cloud.version>Finchley.SR2</spring-cloud.version> </properties> <dependencyManagement> <dependencies> <!-- springCloud --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project>
(3) 创建maven子工程zs200a-user
(4) maven子工程zs200a-user的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"> <parent> <artifactId>zs200a-parent</artifactId> <groupId>com.chaoyue.zs200a</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>com.chaoyue.zs200a</groupId> <artifactId>zs200a-user</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> </project>
(5) 创建maven子工程zs200a-user-interface
(6) maven子工程zs200a-user-interface的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"> <parent> <artifactId>zs200a-user</artifactId> <groupId>com.chaoyue.zs200a</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>com.chaoyue.zs200a</groupId> <artifactId>zs200a-user-interface</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> </dependencies> </project>
(7) zs200a-user-interface工程中新建一个User类
package com.chaoyue.zs200a.user.pojo; import lombok.Data; import java.util.Date; @Data public class User { private Long id; private String username; private String password; private String phone; private Date created; private String salt; }
(8) 创建maven子工程zs200a-user-service
(9) maven子工程zs200a-user-service的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"> <parent> <artifactId>zs200a-user</artifactId> <groupId>com.chaoyue.zs200a</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>com.chaoyue.zs200a</groupId> <artifactId>zs200a-user-service</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>com.chaoyue.zs200a</groupId> <artifactId>zs200a-user-interface</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
(10) zs200a-user-service工程中新建一个UserServiceApplication类
package com.chaoyue.zs200a.user; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @SpringBootApplication @EnableDiscoveryClient public class UserServiceApplication { public static void main(String[] args) { SpringApplication.run(UserServiceApplication.class, args); } }
(11) maven工程整体打包并部署到本地仓库
加载全部内容