SpringBoot mven多模块项目改造

mven多模块项目改造

项目结构

 

  • 父工程

    • hanzheng

  • 子模块

    • hanzheng-model

    • hanzheng-utils

    • hanzheng-dao

    • hanzheng-service

    • hanzheng-task

    • hanzheng-hanzheng

hanzheng-model

  • com

    • xml

      • model

        • dto(dto实体类)

        • pojo(pojo实体类)

        • req(接收请求的实体类)

        • resp(返回数据的实体类)

        • seal(印章业务用到的实体类)

        • xmlpath(解析影像系统返回xml字符串所用实体类)

hanzheng-utils

  • com

    • xml

      • utils(存放项目中用到的一些util)

hanzheng-dao

  • com

    • xml

      • dao(抽出项目中用到的 dao 存放到 dao 模块)

hanzheng-service

  • com

    • xml

      • service(抽出项目中用到的 service serviceimpl 存放到 service 模块)

hanzheng-task

  • com

    • xml

      • task(此模块主要是使用 Spring 定时任务 @Scheduled,完成一些定时任务逻辑)

hanzheng-hanzheng

  • com

    • xml

      • hanzheng(函证项目主要业务模块)

多模块项目中需要注意

  • @Service跨模块引用

    • @SpringBootApplication(scanBasePackages="com.xml.**") 扫描所有com.xml

    • 需要在启动类加上 scanBasePackages 指定 service 在那个模块的目录

  • 启动类 dao 包扫描

    • @MapperScan("com.xml.dao")

    • dao 模块的 resources包里面放 mapper包(.xml文件)

  • .xml 文件 resultType

    • resultType = "com.xml.model.resp.RespCF0008Child"

    • 单体项目抽出 model 后需要修改.xml文件里面的 <select> resultType = "返回实体类的路径"

  • .xml 文件 namespace

    • namespace = "com.xml.dao.ConfirmDao"

    • 单体项目抽出 dao 后需要修改.xml文件里面的 <mapper> namespace = "dao当前所在的路径"

maven 打包

  • 没有启动类的模块加入打包:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <skip>true</skip>
    </configuration>
</plugin>
  • 有启动类的模块打包加入:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <mainClass>com.xml.hanzheng.HanZhengApplication</mainClass>
    </configuration>
</plugin>
​
<mainClass>:模块启动类位置
  • 打包首先父工程需要 clean清理 install安装

 

  • 然后是子模块按照依赖顺序依次 install,如 model 需要首先 install ,他被其他的模块所依赖,他没有安装,其他模块先安装就会出错,找不到。

    • 我这里是 model ——》utils ——》dao ——》 service ——》最后是两个带启动类的模块,这个先后无所谓

  • install 完成 hanzheng(这是带启动类的) 模块执行打包

    • 如下 jar 包里面的东西可以被解压出来

 

  • 解压出来的目录

    • org文件夹下存放的是Spring boot loader模块编译的.class文件,也就是jar启动的关键代码所在。

    • BOOT-INF是存放对应的应用服务的.class文件和Maven依赖的jar包,包括启动类SpringBootTestApplication

      • 这里可以看到 hanzheng-model,hanzheng-service,hanzheng-dao,hanzheng-utils,都打成jar包在这里面

    • META-INF下存放的是Maven相关的pom信息和MANIFEST.MF文件

      • 执行 java -jar 命令的时候,启动类配置在 jar 包目录下 META-INF 文件夹中名为 MANIFEST.MF 的文件中,在这个文件中有一个名为 Main-Class 的属性

      • Main-Class 指向的 Class 为 org.springframework.boot.loader.JarLauncher , JarLauncher是 JAR 的启动器

      • 可以看到项目定义的启动类是指向 Start-Class 这个属性

      • Spring Boot依赖的JAR文件都是存放在BOOT-INF/lib下,而org.springframework.boot.loader.JarLauncher 会将 JAR 作为 SpringBootTestApplication 类库的依赖

     

     org文件夹下存放的是Spring boot loader模块编译的.class文件,也就是jar启动的关键代码所在。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值