【问题标题】:Gretty, Spring MVC and hot deploymentGretty、Spring MVC 和热部署
【发布时间】:2018-05-16 23:14:02
【问题描述】:

我正在学习 Spring MVC 并尝试将它与 Gradle 和 Gretty 插件一起使用。我已经成功创建了一个“Hello World”项目,但是尽管设置了managedClassReload=true,但我无法使用 Gretty 进行热部署。我使用 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 时,会检测到源文件的更改并自动重新加载项目。

可能是什么原因导致 gretty 的热部署不起作用? springloaded 不能和 Spring MVC 一起工作吗?

【问题讨论】:

    标签: java gradle deployment gretty


    【解决方案1】:

    首先,由于org.gretty 已经在官方Gradle plugin repository 中提供了一段时间,因此无需依赖您从github 收集的插件脚本:

    plugins {
      id "org.gretty" version "2.1.0"
    }
    

    由于您正在使用 appRun 就地运行您的应用,因此您的更改不会重新加载。
    您必须使用appRunWar 将您的应用程序作为战争运行。

    这在文档中没有提到。但在 Gretty 源代码中。
    您可以在BaseScannerManager 中查看导致您的问题的 Gretty code

    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)
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-06-17
      • 1970-01-01
      • 2012-06-08
      • 2011-09-29
      • 1970-01-01
      • 1970-01-01
      • 2013-09-27
      • 2015-03-11
      • 1970-01-01
      相关资源
      最近更新 更多