Spring Boot(spring-boot-starter-web)在IntelliJ中热交换功能失效求助
Hey there, let's work through this hot swap issue step by step— I’ve been in your exact situation before and know how frustrating it is when devtools doesn’t kick in as expected!
Double-Check Your DevTools Dependency
Whileruntimescope is valid, let’s confirm your dependency block is clean (and add the optional flag, which helps avoid propagating devtools to other modules accidentally):<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency>Also make sure there are no accidental exclusion rules for devtools in your build file.
Verify IntelliJ’s Hidden Registry Settings
Thecompiler.automake.allow.when.app.runningsetting isn’t the only one that matters. PressCtrl+Shift+A(Windows/Linux) orCmd+Shift+A(Mac), search for Registry, and ensure these two are checked:compiler.automake.allow.when.app.runningactionSystem.assertFocusAccessFromEdt(This can interfere with auto-build triggers if disabled)
Force-Enable DevTools Restart
Sometimes restart gets disabled silently via config. Add these lines to yourapplication.propertiesto explicitly turn it on:spring.devtools.restart.enabled=true # Optional: Specify custom paths to watch if your code lives in non-standard directories spring.devtools.restart.additional-paths=src/main/javaCheck Your Run Configuration
Make sure you’re running the app via IntelliJ’s Spring Boot Run Configuration, not a packaged JAR or external command line. Devtools only works in development mode (when usingspring-boot:runor the IDE’s native run tool).Try a Manual Build Trigger
Even with auto-build enabled, IntelliJ sometimes needs a nudge. After making code changes, pressCtrl+F9(Windows/Linux) orCmd+F9(Mac) to trigger a manual build— this should kick off the devtools restart immediately.Check for Excluded Paths
Devtools ignores certain files by default, but custom exclusions might be blocking your code. Verify yourapplication.propertiesdoesn’t exclude your source directories:# Ensure these don't cover your code paths spring.devtools.restart.exclude=static/**,public/**Invalidate IntelliJ Caches
Stale cache data often causes weird IDE behavior. Go toFile > Invalidate Caches...and select "Invalidate and Restart"— this clears out any corrupted data that might be breaking auto-build.
I’ve fixed this issue more times than I can count, and 90% of the time it was either a missing Registry setting or forgetting to trigger a manual build. Give these steps a shot and let me know which one works for you!
内容的提问来源于stack exchange,提问作者Ron Stevenson

