spring boot 调试

  • maven

  • gradle

 

Maven:

命令行方式:

mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

需要在idea 中edit configuration->+ -> remote->debug

 from

rum main方法:

debug run

热部署

 在pom里添加:

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>
                <dependencies>
                    <!-- spring热部署-->
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>springloaded</artifactId>
                        <version>1.2.6.RELEASE</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

然后修改类后,在idea中重新编译该类:build->recompile XXXX

或者使用快捷键ctrl+shif+F9

Gradle:

近来发现使用gradle的比较多。

热部署:

buildscript {
    repositories { jcenter() }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:1.4.1.BUILD-SNAPSHOT"
        classpath 'org.springframework:springloaded:1.2.0.RELEASE'
    }
}

apply plugin: 'idea'

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

debug启动:

方法1:

采用gradle自带属性debug模式.结果好像不能用啊。直接看方法3吧。

在project根目录下创建gradle.properties.

添加:

org.gradle.debug=true

然后命令行:

gradlew bootRun --debug

看到显示:

接着在idea中 edit configuration->+ -> remote->debug

方法2:

在build.gradle中添加:

bootRun {
    jvmArgs "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"
}

然后:

gradlew bootRun --debug

方法3:

直接:

gradle bootRun --debug-jvm

参考:http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-remote-debug-gradle-run

原文地址:https://www.cnblogs.com/woshimrf/p/springboot-hotload-debug.html