IDEA + Spring Boot + JRebel + MyBatis Mapper XML 热部署不能自动编译的解决方案和启动的几种方式

原文地址:https://blog.zhjh.top/archives/odMZfohqKsKEydNsgIw5N

自动编译

修改文件后,焦点离开 IDEA 后,任务栏会有进度提示。

  1. 启用 Module 的 JRebel 自动编译(Spring MVC 需要此步):打开 IDEA 左侧 Sidebar 中的 JRebel Panel(View -> Tool Windows -> JRebel),然后勾选需要的 Module。
    JRebel Panel
    Jrebel 插件会自动在 resources 目录底下生成一个 rebel.xml。

  2. 允许 IDEA 自动编译:在 Maintenance(Ctrl + Shift + Alt + /) -> Registry 中勾选 compiler.automake.allow.when.app.running(IDEA 新版没有此项,请手动修改后一句的设置),此时 IDEA 会自动选中 Settings -> Build, Execution, Deployment -> Compiler 中的 Build project automatically

如果更改了 Project Structure 导致不能用 JRebel 启动或者启动后不能自动编译,在 Project Structure 不报错的情况下,删除 rebel.xml,重新勾选即可,如果还是没用,在 Project Structure 不报错的情况下,删除 .idea、.iml、rebel.xml 重新导入项目勾选即可。

方式一 Application 类

Run/Debug Configurations 中修改配置。

IDEA 新版要 修改选项(Modifiy options),然后选择**执行“更新”操作时(On ‘Update’ action)切换出 IDE 时(On frame deactivation)**即可。
在这里插入图片描述

Application 类右键选择 Run/Debug with JRebel ‘Application’,或者工具栏运行等。

方式二 bootRun

Maven、Gradle 加载了 org.springframework.boot 插件后,在 Maven、Gradle window 中,找到 spring-boot:run(Module name -> Plugins -> spring-boot) 或者 bootRun(Module name -> Tasks -> application),右键选择 Run/Debug with JRebel ‘Module name’ [spring-boot:run/bootRun]

  • Maven

    <build>
      <plugins>
        <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
      </plugins>
    </build>
    

  • Gradle - groovy

    buildscript {
      ext {
        springBootVersion = "2.0.4.RELEASE"
      }
    
      dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
      }
    }
    
    apply plugin: "org.springframework.boot"
    
  • Gradle - kts

    plugins {
      id("org.springframework.boot") version "2.1.1.RELEASE"
    }
    

    Gradle window

方式三 本地 Tomcat

使用本地 Tomcat 也可以自动编译,就像非 Spring Boot 项目一样,但是此方式启动慢一丢丢。

  1. 新增启动类

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
    
    public class SpringBootInitializer extends SpringBootServletInitializer {
    
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(Application.class);
      }
    }
    
  2. 添加 war 插件:

    直接添加 Artifacts 的话,可能会有些文件没有打包进去导致报错。

  • Maven

    <packaging>war</packaging>
    <dependency>
    ……
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- 移除内置 Tomcat -->
    <exclusions>
      <exclusion>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
      </exclusion>
    </exclusions>
    ……
    </dependency> 
    
  • Gradle - groovy

    apply plugin: 'war'
    
  • Gradle - kts

    plugins {
      war
    }
    apply(plugin = "war")
    

    添加插件后会在 Project Structure -> Project Settings -> Artifacts 自动生成 Web Application: Archive

  1. 配置本地 Tomcat,工具栏使用 JRebel 启动即可:

MyBatis Mapper XML 热部署

市场搜索并安装这个插件即可:
JRebel MyBatis Plus Extension

参考资料

把 spring-boot 项目部署到 tomcat 容器中

  • 14
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 14
    评论
JRebel是一款用于Java开发的热部署工具,可以在不重启应用服务器的情况下,即时生效地将代码修改应用到正在运行的应用程序中。然而,根据引用的信息,JRebelIDEA中对于XML文件的修改无法进行热部署。 这可能是因为JRebelIDEA中对XML文件的热部署支持不完全,而在MyEclipse中可以实现。具体原因可能需要进一步的调查,但一种可能的解释是JRebel对于XML文件的热部署依赖于IDE的特定配置和集成。可能IDEAJRebel在处理XML文件修改的方式上存在差异,导致IDEA中的JRebel无法实现对XML文件的热部署。 为了解决这个问题,你可以尝试以下几点: 1. 确保你的IDEAJRebel都是最新版本,以确保你使用的是最新的修复和改进。 2. 检查IDEAJRebel的相关配置,确保你的项目和服务器配置正确无误。 3. 如果JRebel无法实现对XML文件的热部署,你可以考虑使用其他方式来实现XML文件的即时更新,例如使用自动化构建工具或配置文件热加载库。 综上所述,JRebelIDEA中对XML文件的热部署支持有限。如果你需要对XML文件进行即时更新,你可以尝试其他解决方案或工具。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [使用idea+maven+JRebel热部署,更新xml文件不管用,谁知?](https://blog.csdn.net/liuji0517/article/details/104648403)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值