1.创建项目
2.创建模块
创建时要注意组ID的命名
通常包含以下模块:
项目的pom文件中,依赖如下(web模块不需要依赖,也不需要main文件夹):
3.配置pom文件
1),主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.wnhz.tfe</groupId>
<artifactId>wnhz-2048</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>wnhz-common</module>
<module>wnhz-domain</module>
<module>wnhz-config</module>
<module>wnhz-tools</module>
<module>wnhz-book</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.snapshot.version>1.0-SNAPSHOT</project.snapshot.version>
<project.mybatis-plus.version>3.5.3.1</project.mybatis-plus.version>
<project.druid.version>1.2.18</project.druid.version>
<project.swagger.version>4.3.0</project.swagger.version>
<project.jwt.version>4.3.0</project.jwt.version>
<project.hutools.version>5.8.24</project.hutools.version>
<project.core.version>3.5.0</project.core.version>
</properties>
<!--springboot依赖-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.13</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<!--依赖版本管理-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${project.mybatis-plus.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-annotation</artifactId>
<version>${project.mybatis-plus.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${project.druid.version}</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
<version>${project.swagger.version}</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>${project.jwt.version}</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${project.hutools.version}</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>${project.core.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<!--项目构建-->
<build>
<plugins>
<!-- 编译源代码插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<!-- 打包源代码插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
2),业务模块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>
<parent>
<groupId>com.wnhz.tfe</groupId>
<artifactId>wnhz-2048</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.wnhz.tfe.book</groupId>
<artifactId>wnhz-book</artifactId>
<description>wnhz项目的book业务模块</description>
<dependencies>
<dependency>
<groupId>com.wnhz.tfe.config</groupId>
<artifactId>wnhz-config</artifactId>
<version>${project.snapshot.version}</version>
</dependency>
<dependency>
<groupId>com.wnhz.tfe.common</groupId>
<artifactId>wnhz-common</artifactId>
<version>${project.snapshot.version}</version>
</dependency>
<dependency>
<groupId>com.wnhz.tfe.domain</groupId>
<artifactId>wnhz-domain</artifactId>
<version>${project.snapshot.version}</version>
</dependency>
<dependency>
<groupId>com.wnhz.tfe.tools</groupId>
<artifactId>wnhz-tools</artifactId>
<version>${project.snapshot.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.24</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>3.16.5</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
3),common模块
<?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>
<parent>
<groupId>com.wnhz.tfe</groupId>
<artifactId>wnhz-2048</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.wnhz.tfe.common</groupId>
<artifactId>wnhz-common</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
4),config模块
<?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>
<parent>
<groupId>com.wnhz.tfe</groupId>
<artifactId>wnhz-2048</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.wnhz.tfe.config</groupId>
<artifactId>wnhz-config</artifactId>
<description>项目的的配置文件</description>
</project>
5),domain模块
<?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>
<parent>
<groupId>com.wnhz.tfe</groupId>
<artifactId>wnhz-2048</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.wnhz.tfe.domain</groupId>
<artifactId>wnhz-domain</artifactId>
<dependencies>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-annotation</artifactId>
</dependency>
</dependencies>
</project>
6),tools模块
<?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>
<parent>
<groupId>com.wnhz.tfe</groupId>
<artifactId>wnhz-2048</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.wnhz.tfe.tools</groupId>
<artifactId>wnhz-tools</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
7),web模块没有pom文件
4.其余文件的配置
1),config模块
application-mybatis.yml文件
#配置数据源
spring:
datasource:
druid:
url: jdbc:mysql://192.168.158.130:3306/book_db?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: root
password: 123
driver-class-name: com.mysql.cj.jdbc.Driver
application-redis.yml文件
spring:
redis:
port: 6379
host: 192.168.158.130
database: 0
2),业务模块
application.yml文件
spring:
profiles:
active: dev,mybatis,redis
application-dev.yml文件
server:
port: 11111
logging:
level:
com.wnhz: debug
knife4j:
enable: true
#spring:
# autoconfigure:
# exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
spring:
rabbitmq:
host: 192.168.158.130
username: admin
password: 123
port: 5672
另外两个文件为空