【问题标题】:Spring-boot and spring boot dev tools integration not showing the updated class changesSpring-boot 和 Spring Boot 开发工具集成未显示更新的类更改
【发布时间】:2017-10-11 22:13:21
【问题描述】:

我正在尝试跟随 this example 进行 spring boot 和 spring boot dev tools 集成以进行自动重启。当我运行build --continuous 任务时,构建文件夹中的类正在更新,但应用程序仍然与旧类对话。在示例中,bootRun 任务如下所示。我的项目有运行应用程序的自定义任务。现在使用build -continuous,当我对应用程序进行更改时,它正在重建类,但正在运行的应用程序没有显示更改。如何更改我的自定义 h2Run 任务以加载更改后的类?谢谢。

示例中的开机运行任务

bootRun {
    classpath = sourceSets.main.runtimeClasspath + configurations.dev
}

我的 bootRun 自定义任务

class Run extends JavaExec {
    Run() {
        group "application"
        dependsOn project.tasks.classes, project.tasks.pathingJar
        classpath = project.files("$project.buildDir/classes/main", "$project.buildDir/resources/main", project.tasks.pathingJar.archivePath)
        main = "com.mycompany.Application"
    }
}

task h2Run(type: Run) {
    classpath = sourceSets.main.runtimeClasspath + configurations.dev // this is not working
    description "Start $appName using H2 database"
    args "--spring.profiles.active=dev"
    mustRunAfter 'cleanH2'
    dependsOn copyContentTypeLibraries
}

【问题讨论】:

  • 如果没有人可以回答,请投票。我需要恢复我的声誉。 ;)

标签: spring spring-boot gradle spring-boot-devtools


【解决方案1】:

我浏览了您链接到的 DZone 文章。我没有添加您的自定义 Run 类或任务,我只是从文章中抓取了 bootRun 任务。即使没有您的任何自定义代码,我最初也遇到了与您相同的行为。

文章称:

  1. 在第一个终端,将 Gradle 构建作为一个连续任务启动: gradle build --continuous

  2. 在第二个终端,启动 Gradle bootRun 任务:gradle bootRun

如果我执行这些操作,按此顺序,我还会看到我的类重新编译,但 servlet 容器不会提取更改。就像你描述的那样。

但是,如果我执行 gradle bootRun first 和 gradle build --continuous second,则在应用程序运行后,每当我编辑 java 文件时,应用程序都会按预期重新启动.

您是否尝试过在两个终端窗口中以相反的顺序执行命令?

【讨论】:

  • 你说得对,我不需要添加任何特殊的运行任务。当我们使用 gradle bootRun 任务添加依赖项时,它应该可以工作。
猜你喜欢
  • 2015-12-14
  • 2015-03-22
  • 1970-01-01
  • 2016-08-31
  • 2015-05-29
  • 2020-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多