IntelliJ 15, SpringBoot devtools livereload not working

匿名 (未验证) 提交于 2019-12-03 02:56:01

问题:

Having issues with the new LiveReload feature with Spring Boot devtools 1.3. It doesn't reload on class changes. I've seen it demo'd with IntelliJ @ Devoxx 2015. Is there some IDE setting I need to have enabled? I'm running via the IDE and not through Gradle. I tried enabling "Make project automatically" which doesn't seem to help.

It seems to load correctly and is looking in the correct path

2015-11-23 05:55:30.592 DEBUG 4700 --- [  restartedMain] o.s.boot.devtools.restart.Restarter      : Starting application com.myapp.Application with URLs [file:/E:/Projects/myapp/build/classes/main/, file:/E:/Projects/myapp/build/resources/main/] 

My files

build.gradle

buildscript {     ext {         springBootVersion = '1.3.0.RELEASE'     }     repositories {         mavenCentral()     }     dependencies {         classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")      } }  apply plugin: 'java' apply plugin: 'eclipse-wtp' apply plugin: 'idea' apply plugin: 'spring-boot'  apply plugin: 'war'   war {     baseName = 'myapp'     version = '0.0.1-SNAPSHOT' } sourceCompatibility = 1.8 targetCompatibility = 1.8  repositories {     mavenCentral()     maven { url "https://repo.spring.io/snapshot" }     maven { url "https://repo.spring.io/milestone" } }  configurations {     providedRuntime }  dependencies {     compile('org.springframework.boot:spring-boot-starter-actuator')     compile('org.springframework.boot:spring-boot-devtools')     compile('org.springframework.boot:spring-boot-starter-jdbc')     compile('org.projectlombok:lombok')     compile('org.springframework.boot:spring-boot-starter-web')     compile('net.sourceforge.jtds:jtds:1.3.1');     testCompile('org.springframework.boot:spring-boot-starter-test')  }  dependencyManagement {     imports {          mavenBom "org.springframework.cloud:spring-cloud-starter-parent:Brixton.M3"      } }   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'     } }  task wrapper(type: Wrapper) {     gradleVersion = '2.7' } 

HelloWorldController

@Controller public class HelloWorldController {      @RequestMapping("/")     @ResponseBody     String home(){          return "Hello World test";     } } 

回答1:

I am guessing you are coding and expect DevTools to auto-magically figure out you have changed something in your project? Devtools does that by watching your classpath folder(s). When a .class file (or a resource) has changed, devtools take the appopriate action.

If you don't see anything, that's probably because you're just coding and not updating the classpath. You have to invoke Make Projectthe documentation



回答2:

To solve this You can do like: 1- Add LiveReload extension in your browser. 2- Add devtools dependencies to your pom.xml(if it's maven (spring-boot-devtools)). 3- In your intellij IDEA go to: file->settings->build,execution,deployment. Go to ->compiler->build project automatically. 4-In your intellij IDEA: SHIFT+Ctrl+A ->registry-> compiler.automake.allow.when.app.running



回答3:

LiveReload and restart are different features. Livereload allows you to detect changes in resources/static folder and notify browser that files changed and the page should be reloaded.

Your question describes Restart scenario. If you want your application to reload automatically on *.class-files changes, make sure your IDE outoputs compiled classes to:

build\classes\main 

In Intellij go to Project Structure (Ctrl+Alt+Shift+S) and setup project compiler output dir. After this you can make changes in your classes and press Ctrl+Shift+F9 to recompile current class or hit Ctrl+F9 to recompile the whole project. Spring Boot Devtools will detect changes in build\classes\main and perform restart of your application automatically.

If you want to enable LiveReload for your static assets add the following (otherwise you won't see cahnges of static content while executing bootRun goal):

bootRun {     addResources = true } 


回答4:

From the documentation here

As DevTools monitors classpath resources, the only way to trigger a restart is to update the classpath. The way in which you cause the classpath to be updated depends on the IDE that you are using. In Eclipse, saving a modified file will cause the classpath to be updated and trigger a restart. In IntelliJ IDEA, building the project (Build → Make Project) will have the same effect.



回答5:

Follow below simple steps, you will be up and running in less than 2 minutes.

  1. Press Ctrl+Shift+A
  2. Search for Registry ...
  3. scroll and find "compiler.automake.allow.when.app.running" then select the checkbox to make it active.
  4. Click close
  5. File Menu -> settings ...
  6. Expand Build, Execution, Deployment
  7. Select Compile
  8. Select checkbox Build project automatically
  9. Apply
  10. Click Ok

Now stop your application server and then start your application, that's it you will find automatic restart/reload activated when any changes are detected in the project.

Happy Coding/Hacking.



回答6:

if you use IntelliJ IDEA, adding the spring-boot-devtools is not enough. This is because unlike Eclipse, you need to explicitly tell IntelliJ IDEA to “Make The Project” for it to build to the target classpath.

see on youtube

The easiest solution: run app debug mode and press Ctrl + f9 (short-cut for build)

or

  1. To open the registry, just press SHIFT+CTRL+A. In the registry window, enable the “compiler.automake.allow.when.app.running” check-box.



回答7:

Edit - Macros - Start Macro Recording File - Save All Build - Build Project Edit - Macros - Stop Macro Recording - You can save the macro name as “Save & Make Project” Preferences - Keymap - Macros 

Go down to expand the macros directory to find your newly macro (i.e. “Save & Make Project”). Double click to Add Keyboard Shortcut and press Cmd+S if you use Mac and Ctrl+S if you use Windows.

Intellij will prompt saying that Ctrl+S already exist just click 'Replace'.

Now all set and Ctrl+S should trigger Spring-Boot Devtools

Reference: https://tomyjaya.github.io/2016/10/08/spring-boot-dev-tools-in-intellij/



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!