spring boot和Intellij idea如何实现热加载?

buildscript {
    ext {
        springBootVersion = '1.3.6.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("org.springframework:springloaded:1.2.6.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'idea'

jar {
    baseName = 'spring-boot-blog'
    version = '0.0.1-SNAPSHOT'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-validation')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.thymeleaf:thymeleaf-spring4:3.0.0.RELEASE')
    compile('org.thymeleaf:thymeleaf:3.0.0.RELEASE')
    runtime('mysql:mysql-connector-java')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}


eclipse {
    classpath {
         containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
         containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
    }
}

idea {
    module {
        inheritOutputDirs = false
        outputDir = file("$buildDir/classes/main/")
    }
}

这是我的build配置,设置了Idea的自动编译,然后在命令行用./gradlwe bRun但是没效果.

阅读 13.4k
3 个回答

不知道热加载是不是指的这种修改后自动运行。

Spring boot 提供了devtools,添加devtools的依赖即可

Maven:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

Gradle:

dependencies {
    compile("org.springframework.boot:spring-boot-devtools")
}

eclipse修改保存后可以自动重新运行

IDEA make Project(ctrl+F9)后可以自动重新运行

参考:http://docs.spring.io/spring-...

可以用jrabel

使用 debug 模式启动spring boot,然后按快捷键编译项目(慢)或者单个class(快),这种只适合改了方法里面的逻辑,改了参数或者新加东西了都会报错。你可以试下。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题