1.在pom.xml引入相关依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>1.3.0.RELEASE</version>
<optional>true</optional>
</dependency>
2.“File” -> “Settings” -> “Build,Execution,Deplyment” -> “Compiler”,选中打勾 “Build project automatically” 。
3.组合键:“Shift+Ctrl+Alt+/” ,选择 “Registry” ,选中打勾 “compiler.automake.allow.when.app.running”
在2021版之前的idea一般均可通过上述方法,如若没有可以在setting里面勾选
小细节 勾选compiler.document.save.enabled(指定是否启用保存项目响应当文档被更改),并将它们的对应的保存动作延时时间适当缩小,或者使用默认值也可以、
常见问题
1.启动时出现下图时,该问题是因为组件的版本号而导致的问题
java.lang.IllegalStateException: Restarter has not been initialized
at org.springframework.util.Assert.state(Assert.java:392) ~[spring-core-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.boot.devtools.restart.Restarter.getInstance(Restarter.java:563) ~[spring-boot-devtools-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationPreparedEvent(RestartApplicationListener.java:75) ~[spring-boot-devtools-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.devtools.restart.RestartApplicationListener.onApplicationEvent(RestartApplicationListener.java:48) ~[spring-boot-devtools-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:121) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.boot.context.event.EventPublishingRunListener.contextLoaded(EventPublishingRunListener.java:85) ~[spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at org.springframework.boot.SpringApplicationRunListeners.contextLoaded(SpringApplicationRunListeners.java:66) ~[spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:367) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
at com.*.SpringBootWebApplication.main(SpringBootWebApplication.java:17) [classes/:na]
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<!--将版本号删掉即可-->
<version>1.3.0.RELEASE</version>
<optional>true</optional>
</dependency>