基于Maven和IntelliJ IDEA搭建多模块微服务

这篇具有很好参考价值的文章主要介绍了基于Maven和IntelliJ IDEA搭建多模块微服务。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

基于Spring Boot、Spring Cloud、Spring Cloud Alibaba的微服务开发,组件众多。因此,在创建项目伊始,就应当考虑版本的管理。以Spring Boot的版本升级发布为基础,Spring Cloud的版本升级发布,会匹配Spring Boot升级发布的版本。Spring Cloud Alibaba版本升级发布,会匹配Spring Boot和Spring Cloud的版本升级发布的版本

本例版本:

Spring Boot 2.6.3
Spring Cloud 2021.0.1
Spring Cloud Alibaba 2021.0.1.0
Apache Maven 3.6.3
IntelliJ IDEA 2021.2.3
JDK 1.8
Spring Framework 5.3.15

本例实现基于Maven和IntelliJ IDEA搭建多模块微服务项目(工程)。

第一层级工程,只管理第二层级工程。

第二层级工程,管理第三层级工程。

以此类推,使用pom.xml中的modules和module标签管理维护关系。

1.规划微服务

规划微服务如表格。

idea创建微服务项目,java项目搭建,maven,intellij-idea,微服务

2.创建hub-example

hub-example,是顶级工程,是一个聚合工程,用来管理工程所有模块。在hub-example中的src目录不写代码,可以删除。在pom.xml中打包方式配置为pom。

2.1 创建Maven工程

运行IDEA,依次选择菜单File->New->Project进入New Project对话框,如下配置。

idea创建微服务项目,java项目搭建,maven,intellij-idea,微服务

 2.2 配置工程信息

hub-example工程配置信息。

idea创建微服务项目,java项目搭建,maven,intellij-idea,微服务

 2.3 创建完成

项目创建完成如图,项目初始列表,pom.xml初始化文件

idea创建微服务项目,java项目搭建,maven,intellij-idea,微服务

 3.配置hub-example的pom.xml

配置hub-example的pom.xml,包括以下几点内容,细节在pom.xml查看。

(1)配置打包方式。

(2)配置核心依赖。

(3)配置版本管理。

(4)配置打包插件。

(5)配置yml文件读取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.hub</groupId>
    <artifactId>hub-example</artifactId>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>hub-dependencies</module>
        <module>hub-common</module>
        <module>hub-ware</module>
    </modules>

    <!--(1)配置打包方式(2)配置核心依赖(3)配置版本管理(4)配置打包插件(5)配置yml文件读取pom文件的标签值。-->

    <!--聚合工程,打包方式:pom-->
        <packaging>pom</packaging>
        <!-- 版本管理 -->
        <properties>
            <maven.compiler.source>8</maven.compiler.source>
            <maven.compiler.target>8</maven.compiler.target>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <java.version>1.8</java.version>
            <spring.boot.version>2.6.3</spring.boot.version>
            <spring.cloud.version>2021.0.1</spring.cloud.version>
            <spring.cloud.alibaba.version>2021.0.1.0</spring.cloud.alibaba.version>
            <!-- 统一管理hub-example的版本,在子模块直接使用此版本即可-->
            <hub.example.version>1.0-SNAPSHOT</hub.example.version>
            <spring.boot.maven.plugin.version>2.6.3</spring.boot.maven.plugin.version>
            <mysql.version>5.1.47</mysql.version>
            <druid.version>1.1.23</druid.version>
            <pagehelper.version>1.4.1</pagehelper.version>
            <mybatis.version>2.2.0</mybatis.version>
            <mybatis-plus.version>3.3.1</mybatis-plus.version>
            <lombok.version>1.18.18</lombok.version>
            <fastjson.version>1.2.83</fastjson.version>
            <hutool.version>5.7.22</hutool.version>
            <commons.lang3.version>3.12.0</commons.lang3.version>
            <commons.io.version>2.11.0</commons.io.version>
        </properties>
        <!-- 核心依赖   -->
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-dependencies</artifactId>
                    <version>${spring.boot.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-dependencies</artifactId>
                    <version>${spring.cloud.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
                <dependency>
                    <groupId>com.alibaba.cloud</groupId>
                    <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                    <version>${spring.cloud.alibaba.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
        <build>
            <!-- yml文件读取pom文件的标签值 -->
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
            <plugins>
                <!-- 配置打包插件 -->
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>${spring.boot.maven.plugin.version}</version>
                    <configuration>
                        <fork>true</fork>
                        <addResources>true</addResources>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <profiles>
            <profile>
                <!-- yml配置文件环境切换: dev/test/prod -->
                <id>env</id>
                <properties>
                    <profiles.active>dev</profiles.active>
                </properties>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
            </profile>
        </profiles>

</project>

4.hub-example添加模块

hub-example添加的模块也是聚合工程,主要包括:

(1)hub-dependencies,集中管理依赖。聚合工程,不写代码,可以删除src目录。其子模块作用,在pom.xml文件引入常用的依赖。项目中其它工程只要引用hub-dependencies的子模块就行。

(2)hub-common,管理封装的通用模块。聚合工程,不写代码,可以删除src目录。封装的通用代码放在这个模块的子模块中,给每个需要的工程引用。减少重复代码,提供代码可复用度。

(3)hub-ware,管理独立运行的微服。每个业务规划一个微服务。

以hub-dependencies添加子模块为例,归纳以下步骤。

4.1 新建Module

选中hub-example,右键,依次选择:New->Module,进入模块配置对话框。

idea创建微服务项目,java项目搭建,maven,intellij-idea,微服务

4.2 配置Module版本和方式

选择Maven方式、选择JDK版本。

idea创建微服务项目,java项目搭建,maven,intellij-idea,微服务

 4.3 配置Module基础信息

配置hub-dependencies基础信息。

idea创建微服务项目,java项目搭建,maven,intellij-idea,微服务

 4.4 添加剩余模块

按照以上步骤,添加完成hub-common、hub-ware。

4.5 hub-example的pom.xml文件

hub-example的pom.xml文件中新增了<modules>标签即如下。即hub-example管理以下包含的模块。

    <modules>
        <module>hub-dependencies</module>
        <module>hub-common</module>
        <module>hub-ware</module>
    </modules>

5.hub-dependencies添加模块

hub-dependencies添加hub-pf-a-dependencies和hub-pf-b-dependencies模块。

5.1 新建Module

选中hub-dependencies,右键,依次选择:New->Module,进入模块配置对话框。

idea创建微服务项目,java项目搭建,maven,intellij-idea,微服务

 5.2 配置Module版本和方式

选择Maven方式、选择JDK版本。

idea创建微服务项目,java项目搭建,maven,intellij-idea,微服务

 5.3 配置Module基础信息

配置hub-pf-a-dependencies基础信息。

idea创建微服务项目,java项目搭建,maven,intellij-idea,微服务

 5.4 添加剩余模块

按照以上步骤,添加完成hub-pf-b-dependencies。

5.5 hub-dependencies工程的pom.xml

添加模块后,hub-dependencies工程的pom.xml。

<?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>hub-example</artifactId>
        <groupId>com.hub</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>hub-dependencies</artifactId>
    <packaging>pom</packaging>
    <modules>
        <module>hub-pf-a-dependencies</module>
        <module>hub-pf-b-dependencies</module>
    </modules>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

</project>

6.hub-common添加模块

根据5.hub-dependencies添加模块的步骤:

给hub-common添加example-common-entity和example-common-utils模块。

6.1 hub-common工程的pom.xml

添加模块后,hub-common工程的pom.xml。

<?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>hub-example</artifactId>
        <groupId>com.hub</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>hub-common</artifactId>
    <packaging>pom</packaging>
    <modules>
        <module>example-common-entity</module>
        <module>example-common-utils</module>
    </modules>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

</project>

7.hub-ware添加模块

根据5.hub-dependencies添加模块的步骤:

给hub-ware添加example-biz-a和example-biz-b模块。

7.1 hub-ware工程的pom.xml

添加模块后,hub-ware工程的pom.xml。

<?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>hub-example</artifactId>
        <groupId>com.hub</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>hub-ware</artifactId>
    <packaging>pom</packaging>
    <modules>
        <module>example-biz-a</module>
        <module>example-biz-b</module>
    </modules>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
    
</project>

8.hub-example工程列表

创建工程和添加子模块后,工程hub-example工程列表。每个工程上一级和下一级都是通过pom.xml来维护管理关系。

idea创建微服务项目,java项目搭建,maven,intellij-idea,微服务

9.hub-dependencies的子模块添加依赖

为hub-dependencies模块的子模块hub-pf-a-dependencies和hub-pf-b-dependencies模块添加依赖。

9.1 hub-pf-a-dependencies依赖

hub-pf-a-dependencies依赖,主要是基础Jar包。

<?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>hub-dependencies</artifactId>
        <groupId>com.hub</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>hub-pf-a-dependencies</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

        <dependencies>
            <!--基础工具-->
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${lombok.version}</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>${fastjson.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>${commons.lang3.version}</version>
            </dependency>
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>${commons.io.version}</version>
            </dependency>
            <dependency>
                <groupId>cn.hutool</groupId>
                <artifactId>hutool-all</artifactId>
                <version>${hutool.version}</version>
            </dependency>
        </dependencies>

</project>

9.2 hub-pf-b-dependencies依赖

hub-pf-a-dependencies依赖,主要是操作数据库的Jar包。

<?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>hub-dependencies</artifactId>
        <groupId>com.hub</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>hub-pf-b-dependencies</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <!--数据库操作-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>
        <!--连接池-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>${druid.version}</version>
        </dependency>

        <!--PageHelper分页插件-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>${pagehelper.version}</version>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>${mybatis-plus.version}</version>
        </dependency>
    </dependencies>

</project>

10.hub-common的子模块添加依赖

为hub-common模块的子模块example-common-entity和example-common-utils模块添加依赖。

<?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>hub-common</artifactId>
        <groupId>com.hub</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>example-common-utils</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

        <dependencies>
            <dependency>
                <groupId>com.hub</groupId>
                <artifactId>hub-pf-a-dependencies</artifactId>
                <version>${hub.example.version}</version>
            </dependency>
        </dependencies>

</project>

11.hub-ware添加依赖

为hub-ware模块的子模块example-biz-a模块添加依赖。

11.1 example-biz-a依赖

example-biz-a需求:基础依赖、数据库操作依赖、springboot依赖。

注意:spring-boot、spring-cloud、spring-cloud-alibaba,在hub-example中已经引入顶级依赖。在子工程中使用其模块,可以不需要加版本号。

<?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>hub-ware</artifactId>
        <groupId>com.hub</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>example-biz-a</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

        <dependencies>

            <!--springboot依赖-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>

            <!--基础依赖-->
            <dependency>
                <groupId>com.hub</groupId>
                <artifactId>hub-pf-a-dependencies</artifactId>
                <version>${hub.example.version}</version>
            </dependency>

            <!--数据库操作依赖-->
            <dependency>
                <groupId>com.hub</groupId>
                <artifactId>hub-pf-b-dependencies</artifactId>
                <version>${hub.example.version}</version>
            </dependency>
        </dependencies>

    <!--example-biz-a打包成可执行Jar包-->
    <packaging>jar</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring.boot.maven.plugin.version}</version>
                <configuration>
                    <fork>true</fork>
                    <addResources>true</addResources>
                </configuration>
                <executions>
                    <execution>
                        <!-- 把依赖包打包到可执行的jar包中-->
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

11.2 example-biz-a打包成可执行Jar包

example-biz-a打包成可执行Jar包,则在pom.xml中添加配置。

<packaging>jar</packaging>
<build>
 <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>${spring.boot.maven.plugin.version}</version>
    <configuration>
        <fork>true</fork>
        <addResources>true</addResources>
    </configuration>
    <executions>
      <execution>
          <!-- 把依赖包打包到可执行的jar包中-->
          <goals>
              <goal>repackage</goal>
          </goals>
      </execution>
    </executions>
   </plugin>
 </plugins>
</build>

12.1在example-biz-a模块中创建一个包com.htb,并在该包下创建一个启动类BizAApplication

idea创建微服务项目,java项目搭建,maven,intellij-idea,微服务

启动类代码如下:

package com.hub;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
public class BizAApplication {
    public static void main(String[] args) {
        SpringApplication.run(BizAApplication.class, args);
        System.out.println("BizAApplication模块启动成功!!");
    }
}

12.2在resources包下创建application.yml配置数据库连接池和分页插件参数,代码如下:

# tomcat端口号
server:
  port: 8080
# spring配置
spring:
  application:
    # 程序名
    name: example-biz-a
  # 数据源配置
  datasource:
    druid:
      username: root
      password: root
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
# 配置mybatis
mybatis:
  configuration:
    # 将下划线映射成驼峰命名
    map-underscore-to-camel-case: true
    # 指定日志的实现类,在控制台显示SQL语句
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  # 给实体类指定别名,在resultType中不用指定类全名,使用类简单名字即可 (多个包使用逗号分隔)
  #type-aliases-package: com.itheima.reggie.entity,com.itheima.reggie.dto
  # 指定映射文件目录 mybatis中实体映射文件xml所在的目录
  mapper-locations: classpath:mapper/*.xml
# 分页组件
pagehelper:
  # 合理化分页,如果为true,pageNum < 1 会查询第1页 pageNum > 最后一页 会查询最后一页的数据
  # 如果设置为false,pageNum < 1 或 pageNum > 最后一页 会返回空的数据
  reasonable: true
  # 指定使用哪种数据库
  helper-dialect: mysql

12.3开启动类BizAApplication,spring和pagehelper分页组件启动成功!!


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.6.3)

2024-02-25 11:49:31.216  INFO 12620 --- [           main] com.hub.BizAApplication                  : Starting BizAApplication using Java 1.8.0_221 on LAPTOP-MN4GQ4TM with PID 12620 (D:\java_code\2024test\hub-example\hub-ware\example-biz-a\target\classes started by HONOR in D:\java_code\2024test\hub-example)
2024-02-25 11:49:31.216  INFO 12620 --- [           main] com.hub.BizAApplication                  : No active profile set, falling back to default profiles: default
2024-02-25 11:49:31.682  WARN 12620 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.hub]' package. Please check your configuration.
2024-02-25 11:49:31.944  INFO 12620 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2024-02-25 11:49:31.944  INFO 12620 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2024-02-25 11:49:31.944  INFO 12620 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.56]
2024-02-25 11:49:32.016  INFO 12620 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2024-02-25 11:49:32.016  INFO 12620 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 759 ms
2024-02-25 11:49:32.242  INFO 12620 --- [           main] c.a.d.s.b.a.DruidDataSourceAutoConfigure : Init DruidDataSource
2024-02-25 11:49:32.309  INFO 12620 --- [           main] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} inited
 _ _   |_  _ _|_. ___ _ |    _ 
| | |\/|_)(_| | |_\  |_)||_|_\ 
     /               |         
                        3.3.1 
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.


,------.                           ,--.  ,--.         ,--.                         
|  .--. '  ,--,--.  ,---.   ,---.  |  '--'  |  ,---.  |  |  ,---.   ,---.  ,--.--. 
|  '--' | ' ,-.  | | .-. | | .-. : |  .--.  | | .-. : |  | | .-. | | .-. : |  .--' 
|  | --'  \ '-'  | ' '-' ' \   --. |  |  |  | \   --. |  | | '-' ' \   --. |  |    
`--'       `--`--' .`-  /   `----' `--'  `--'  `----' `--' |  |-'   `----' `--'    
                   `---'                                   `--'                        is intercepting.

2024-02-25 11:49:32.765  INFO 12620 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2024-02-25 11:49:32.781  INFO 12620 --- [           main] com.hub.BizAApplication                  : Started BizAApplication in 1.861 seconds (JVM running for 2.476)
BizAApplication模块启动成功!!

Process finished with exit code -1

13总结:避坑记录:

13.1: pagehelper分页组件版本问题导致循环依赖报错原来版本为1.4.0.启动效果为:

idea创建微服务项目,java项目搭建,maven,intellij-idea,微服务

解决方法:将分页组件版本改为1.4.1完美解决

13.2:数据库连接池参数错误导致报错:

数据库连接池参数为:com.mysql.jdbc.Driver

idea创建微服务项目,java项目搭建,maven,intellij-idea,微服务

解决方法:将数据库连接池名称改为:com.mysql.cj.jdbc.Driver文章来源地址https://www.toymoban.com/news/detail-842725.html

到了这里,关于基于Maven和IntelliJ IDEA搭建多模块微服务的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • IDEA maven 向项目添加模块时出错创建项目失败

            选择 java 版本为1.8构建 即可成功,第一次maven项目建立的时候下图红框内容如图即可           通常发生在重设 maven 路径|仓库之后         请检查环境变量 或者更换版本 1--配置本地仓库:      修改maven 安装目录 conf/settings.xml      打开setting,搜索

    2024年02月06日
    浏览(32)
  • 基于 IDEA 创建 Maven 工程

    Maven工程相对之前的项目,多出一组gavp属性,gav(表示当前工程的坐标)需要我们在创建项目的时候指定,p(表示打包方式)有默认值(默认为 jar 包,因此在 java 中无无需单独设置),我们先行了解下这组属性的含义: Maven 中的 GAVP 是指 GroupId、ArtifactId、Version、Packaging 等

    2024年01月25日
    浏览(31)
  • 【Maven】003-基于 IDEA 创建 Maven 工程

    Maven工程的 GAVP 指的是 Group、Artifact、Version、Packaging。这是 Maven 项目的 基本坐标 ,用于 唯一标识和定位 项目。 Group(组织) : 表示项目所属的组织或公司,一般以域名的反转形式命名。例如, com.example 。 Artifact(项目名) : 表示项目的名称,即项目的唯一标识符。例如,

    2024年01月21日
    浏览(30)
  • IntelliJ IDEA创建Web项目并使用Web服务器----Tomcat

    以下是本篇文章正文内容,下面案例可供参考(提示:本篇文章属于原创,请转发或者引用时注明出处。),大家记得支持一下!!!! 每日清醒: ✌✌✌♘慢慢来,谁还没有一个努力的过程。🏆 一定要注意:别忘了设置好之后点击应用!!!!!!!!! maven项目的重点

    2024年02月10日
    浏览(44)
  • IDEA 中搭建 Spring Boot Maven 多模块项目 (父SpringBoot+子Maven)

    [Ref] 新建一个SpringBoot项目 删除无用的 .mvn 目录、 src 目录、 mvnw 及 mvnw.cmd 文件,最终只留 .gitignore 和 pom.xml ① 删除 dependencies 标签及其中的 spring-boot-starter 和 spring-boot-starter-test 依赖,因为 Spring Boot 提供的父工程已包含,并且父 pom 原则上都是通过 dependencyManagement 标签管理

    2024年01月20日
    浏览(57)
  • Windows Java JavaFX IntelliJ IDEA 开发环境搭建 创建工程 编译运行 打包分发 自定义运行时

    博文目录 JavaFX 官网 官网 Getting Started with JavaFX JavaFX 是一个开源的下一代客户端应用程序平台,适用于基于 Java 构建的桌面、移动和嵌入式系统。它是许多个人和公司的协作成果,目标是为开发富客户端应用程序生成一个现代、高效且功能齐全的工具包。 JavaFX 主要致力于富

    2024年02月05日
    浏览(86)
  • 基于IDEA使用maven创建hibernate项目

                新建好了数据库后,若没有建表,可以写了 “类名.hbm.xml” 文件后,有hibernate 自动建表。 如果使用 “类名.hbm.xml” 来实现映射的话,可以在表对应的实体类的包下,新建 “类名.hbm.xml” 文件来实现映射。 示例: 如果已经提前建好数据库和表,这里可以使用

    2024年02月10日
    浏览(44)
  • Intellij IDEA中怎么配置Maven?

    在IntelliJ IDEA中配置Maven非常简单,以下是详细步骤: 步骤1:安装Maven 首先确保你的计算机上已经安装了Maven。如果没有安装,你可以从Apache Maven官网下载并安装:https://maven.apache.org/download.cgi 步骤2:在IntelliJ IDEA中配置Maven 打开 IntelliJ IDEA,点击顶部菜单栏的 “File”(Window

    2024年02月20日
    浏览(41)
  • 使用IntelliJ IDEA 配置Maven(入门)

    使用IntelliJ IDEA配置Maven时,需要按照以下步骤进行操作。请注意,由于涉及到软件安装和配置,以下步骤可能会因为版本更新而略有变化。 1、下载并安装IntelliJ IDEA 首先,需要下载并安装最新版本的IntelliJ IDEA集成开发环境。你可以从官方网站(https://www.jetbrains.com/idea/)下载

    2024年02月19日
    浏览(39)
  • IntelliJ IDEA(简称Idea) 基本常用设置及Maven部署---详细介绍

    前言:            众所周知,现在有许多编译工具,如eclipse,pathon, 今天所要学的Idea编译工具  Idea是JetBrains公司开发的一款强大的集成开发环境(IDE),主要用于Java开发。它提供了丰富的功能和工具,使开发人员可以更高效地编写、调试和测试代码,相比于eclipse编译工

    2024年02月13日
    浏览(41)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包