Devtools does not work if the app is started on the command line unless forking is enabled. Since we want a smooth experience of devtools, we should consider enabling forking in the parent so that it becomes the default.
Any downside to that approach?
Comment From: wilkinsona
bootRun
always forks so no downsides from a Gradle perspective.
An alternative could be to fork in Maven based on whether or not spring-boot-devtools
is on the classpath.
Comment From: snicoll
Actually, I much prefer that. We already fork based on the presence of an agent or jvmArguments so checking for devtools is just one more easy step to take.
Comment From: snicoll
@wilkinsona can we go as far as doing this in 1.4.1
?
Comment From: wilkinsona
I think so. The current behaviour isn't useful and it's inconsistent with how the Gradle plugin behaves.
Comment From: ltsallas
Hi guys,
I have a Spring Boot 1.4.0 based project. I just noticed two things related to this issue after updating to version 1.4.1.
In IntelliJ Idea(Windows) I have set up a maven configuration "spring-boot:run -Dserver.port=8181" .
When executing the goal from the IDE - server.port parameter is ignored and Tomcat starts in the default port 8080. Same happens when executing the goal from a terminal(bug?) - when running the configuration in DEBUG mode, only the parent process is getting killed after pressing the stop button, and you cannot start the app again without manually killing the running process. This one might be related to the IDE.
Setting
Comment From: bclozel
Please take a look at the plugin documentation.
In your case:
mvn spring-boot:run -DjvmArgs="server.port=8181"
Or
SERVER_PORT=8181 mvn spring-boot:run
Also: IntelliJ IDEA has native Spring Boot support, so there are easier ways to do this.
Comment From: ltsallas
Thanks a lot for the link. It clears things up. I was able to pass the parameter with
mvn spring-boot:run -Drun.jvmArguments="-Dserver.port=8181"
I am using the community edition this is why I need plain maven.
Comment From: CubeOfCheese
Hello I use the maven build plugin from the commandline and cannot get devtools to work. Forking is enabled:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.0.RELEASE</version>
<configuration>
<fork>true</fork>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
devtools dependency is in dependencies section of pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
startup output:
2020-11-28 20:58:03.581 INFO 21988 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-11-28 20:58:03.581 INFO 21988 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
startup output with debugging on:
2020-11-28 21:15:10.995 DEBUG 22225 --- [ restartedMain] o.s.boot.devtools.restart.Restarter : Creating new Restarter for thread Thread[main,5,main]
2020-11-28 21:15:10.995 DEBUG 22225 --- [ restartedMain] o.s.boot.devtools.restart.Restarter : Immediately restarting application
2020-11-28 21:15:10.995 DEBUG 22225 --- [ restartedMain] o.s.boot.devtools.restart.Restarter : Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@7a8e95f4
2020-11-28 21:15:10.995 DEBUG 22225 --- [ restartedMain] o.s.boot.devtools.restart.Restarter : Starting application com.appengine.backend.Application with URLs [file:/Users/cubeo/ethicli/Website-and-Backend/target/classes/]
I'm at a loss for what the problem could be. I've tried everything I could think of.
- I made sure forking is enabled by adding it to the config in pom
- There's no use of
SpringApplication.setRegisterShutdownHook(false)
in the codebase - I changed the name of the application directory (was previously springboot)
- We do not override getResource
I'm happy to provide any other info. In the meantime, I'll just keep restarting the dev server Thank you
Comment From: snicoll
@CubeOfCheese forking is enabled by default so you shouldn't have to do anything with recent Spring Boot versions. Perhaps you're missing the bits that the classpath has to be updated? Changing resources or code won't restart the server, you need to update the classpath as described in the documentation (see Triggering a restart). Arguably, this makes it harder to use it with only Maven, see #5136 for some more rationale.
Going forward, please do not comment on an issue to ask for support, especially on a closed one. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.
Comment From: CubeOfCheese
@snicoll Sorry about commenting for support. I'll use gitter in the future (just discovered it)
I realized that simply saving the file in a text editor wasn't sufficient and I instead needed to run mvn compile
I submitted a PR to update the docs to help make this more obvious to future users. https://github.com/spring-projects/spring-boot/pull/24271
It's a shame that the work necessary for #5136 was so substantial and out of scope. Thanks for your help