How to debug spring-boot application with IntelliJ IDEA community Edition?

后端 未结 9 2145
野性不改
野性不改 2021-01-29 23:43

I\'m having difficulties in debugging a Java spring-boot application on IntelliJ IDEA community Edition. The main problem is, that the IDE won\'t stop on a breakpoint, even the

相关标签:
9条回答
  • 2021-01-30 00:07

    I found that including Spring Dev Tools in my build caused IntelliJ debugging to break (per your description above). If you don't use this feature, then simply remove it from your build.

    If using Maven, the lines below should be removed from you pom.xml.

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
    
    0 讨论(0)
  • 2021-01-30 00:08

    The only way I got it working was by creating a separate, remote debug configuration.

    So go to edit configurations-> Remote -> +. Then start your application normally through intelliJ. Then switch to the newly created remote configuration. Instead of running it, press debug. Now debugger should be ready, and you can set breakpoints and the debugger will stop to them.

    EDIT: For me the debug port was already enabled, but I see that this is not the case for everyone. If you get an error like

    'Unable to open debugger port (localhost:5005): java.net.ConnectException "Connection refused: connect"
    

    Then you need to enable port on your app's pom.xml. Copied from @Gianluca Musa answer:

    <plugin>
    <groupId>org.springframework.boot</groupId>
    <configuration>
    <jvmArguments>
    -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
    </jvmArguments>
    </configuration>
    </plugin>
    

    Kudos for @Gianluca Musa for pointing this out in his answer

    0 讨论(0)
  • 2021-01-30 00:14

    The only approach that worked for me, is running or debugging application directly from Intellij Idea. Just open class which contains

     public static void main(String[] args) {
            SpringApplication.run(MyApp.class, args);
        }
    

    And click right mouse button->Debug my application

    0 讨论(0)
提交回复
热议问题