微服务
大约 2 分钟微服务微服务
微服务
新建项目
操作简单,直接打开idea创建新的project,起一个心仪的名字,选好jdk版本即可
注意
创建完成项目后,首先去Setting/PPreferences->Maven里修改Maven配置
项目里面的src目录可以直接删掉,只留下pom文件即可
项目版本
Spring Boot、Spring Cloud使用官网支持的长期维护的最新版本即可 Spring Cloud Alibaba的版本,参见https://github.com/alibaba/spring-cloud-alibaba/wiki/版本说明
添加版本依赖管理
在pom文件中添加<dependencyManagement></dependencyManagement>
<?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>top.jingxc.boot</groupId>
<artifactId>jingxc-spring-boot-starter</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>jingxc-spring-boot-common</module>
</modules>
<name>jingxc-spring-boot-starter</name>
<description>jingxc-spring-boot-starter for String Boot</description>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<springboot.version>2.3.2.RELEASE</springboot.version>
<springcloud.version>Hoxton.SR9</springcloud.version>
<alibaba.version>2.2.6.RELEASE</alibaba.version>
<log4j.version>1.2.17</log4j.version>
<fastjson.version>1.2.47</fastjson.version>
<mybatis.spring.boot.version>3.1.2</mybatis.spring.boot.version>
<common.version>3.7</common.version>
<druid.version>1.1.16</druid.version>
<mysql.version>5.1.47</mysql.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${springboot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--spring cloud Hoxton.SR1-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${springcloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis.spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${common.version}</version>
</dependency>
<!-- druid-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
导入项目
eclipse项目导入流程
- 1.下载最新版的lombok文件: https://projectlombok.org/downloads/lombok.jar
- 2.配置.ini文件,例:
-Xbootclasspath/a:lombok.jar
-javaagent:/Applications/SpringToolSuite4.app/Contents/Eclipse/lombok.jar
- 3.导入maven项目
idea项目导入流程
- 1.直接从软件下载install,lombok即可,导入maven项目
新建模块Modules
直接新建moudle即可,后续开发均在各个模块中,对应着不同的微服务, 创建common(公共模块),后续的一些通用的功能,均在此模块中开发