我正在学习Spring,并试图与Gradle和Gretty插件一起使用它。我已经成功地创建了一个"Hello“项目,但是我无法使用Gretty的热部署,尽管设置了managedClassReload=true。我使用来自appRun的IntelliJ 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一起工作吗?
发布于 2018-05-17 19:07:58
首先,不需要依赖从github收集的插件脚本,因为org.gretty在官方的Gradle插件库中已经有一段时间了:
plugins {
id "org.gretty" version "2.1.0"
}由于您正在使用appRun运行您的应用程序,所以您的更改将不会被重新加载。
您必须使用appRunWar作为war运行应用程序。
这一点在文档中没有提到。但在Gretty源代码中。
您可以检查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)
}
}https://stackoverflow.com/questions/50381193
复制相似问题