Java Gretty、Spring MVC和热部署

Java Gretty、Spring MVC和热部署,java,gradle,deployment,gretty,Java,Gradle,Deployment,Gretty,我正在学习SpringMVC,并尝试将其与Gradle和Gretty插件一起使用。我已经成功创建了一个“Hello World”项目,但是我无法使用Gretty的热部署,尽管设置了managedClassReload=true。我使用IntelliJ的appRungretty任务运行应用程序。我的build.gradle如下所示: apply plugin: 'java' apply plugin: 'application' apply plugin: 'war' apply from: 'h

我正在学习SpringMVC,并尝试将其与Gradle和Gretty插件一起使用。我已经成功创建了一个“Hello World”项目,但是我无法使用Gretty的热部署,尽管设置了
managedClassReload=true
。我使用IntelliJ的
appRun
gretty任务运行应用程序。我的
build.gradle
如下所示:

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'war'
apply from: 'https://raw.github.com/gretty-gradle-plugin/gretty/master/pluginScripts/gretty.plugin'

group = 'lukeg'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
mainClassName = 'lukeg.LearnApplication'

repositories {
    mavenCentral()
    maven {
        url 'https://repo.spring.io/libs-snapshot'
    }
}


dependencies {
    compileOnly('org.projectlombok:lombok:+')
    compile('org.springframework:spring-webmvc:4.3.17.RELEASE')
    compile("org.aspectj:aspectjweaver:1.8.11")
    compile('org.springframework:spring-context:4.3.18.BUILD-SNAPSHOT')
    providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
}

gretty {
    httpPort = 8080
    contextPath = '/'
    servletContainer = 'tomcat9'
    //reloadOnClassChange=true
    managedClassReload=true
    loggingLevel='DEBUG'
}
无论我对servlet容器使用
tomcat9
还是
jetty9
,日志都不会显示Gretty检测到对项目中源文件的更改

有趣的是,当我注释掉
managedClassReload=true
行并取消注释
reloadOnClassChange=true
时,会检测到对源文件的更改,并自动重新加载项目


格雷蒂的热部署不起作用的原因是什么?springloaded不能与Spring MVC一起工作吗?

首先,不需要依赖您从github收集的插件脚本,因为
org.gretty
已经在官方提供了一段时间:

plugins {
  id "org.gretty" version "2.1.0"
}
由于您正在使用在原地运行应用程序,因此不会重新加载您所做的更改。
您必须使用war运行应用程序

文档中没有提到这一点。但是在Gretty源代码中。
您可以在
BaseScannerManager
中检查导致您出现问题的原因:

if(wconfig.reloadOnClassChange) 
{
    if(managedClassReload) 
    {
        if(wconfig.inplace) // <-- your problem, you are running inplace
        {
            log.info 'file {} is in managed output of {}, servlet-container will not be restarted', f, wconfig.projectPath
        }
        else 
        {
            log.info 'file {} is in output of {}, but it runs as WAR, servlet-container will be restarted', f, wconfig.projectPath
            webAppConfigsToRestart.add(wconfig)
        }
    } 
    else 
    {
       log.info 'file {} is in output of {}, servlet-container will be restarted', f, wconfig.projectPath
       webAppConfigsToRestart.add(wconfig)
    }
}
if(wconfig.reloadOnClassChange)
{
如果(managedClassReload)
{
如果(wconfig.inplace)//