Maven搭建springboot项目的方法步骤

来自:互联网
时间:2020-05-26
阅读:
免费资源网 - https://freexyz.cn/

Maven搭建springboot项目

本文是基于Windows 10系统环境,使用Maven搭建springboot项目

Windows 10 apache-maven-3.6.0 IntelliJ IDEA 2018.3.4 x64

一、springboot项目搭建

(1) 新建目录

在某个可用目录下,新建一个文件夹,本文新建目录为 D:demozs200

(2) 创建maven父工程zs200a-parent

Maven搭建springboot项目的方法步骤

Maven搭建springboot项目的方法步骤

填写项目maven坐标

Maven搭建springboot项目的方法步骤

填写项目名称和路径

Maven搭建springboot项目的方法步骤

(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

Maven搭建springboot项目的方法步骤

Maven搭建springboot项目的方法步骤

Maven搭建springboot项目的方法步骤

(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

Maven搭建springboot项目的方法步骤

Maven搭建springboot项目的方法步骤

Maven搭建springboot项目的方法步骤

Maven搭建springboot项目的方法步骤

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

Maven搭建springboot项目的方法步骤

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

Maven搭建springboot项目的方法步骤

Maven搭建springboot项目的方法步骤

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

Maven搭建springboot项目的方法步骤

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工程整体打包并部署到本地仓库

Maven搭建springboot项目的方法步骤

到此这篇关于Maven搭建springboot项目的方法步骤的文章就介绍到这了,更多相关Maven搭建springboot内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

免费资源网 - https://freexyz.cn/
返回顶部
顶部