spring-projects / spring-boot

Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss.
https://spring.io/projects/spring-boot
Apache License 2.0
75.23k stars 40.7k forks source link

Enable forking for `spring-boot:run` if devtools is present #5137

Closed snicoll closed 8 years ago

snicoll commented 8 years ago

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?

wilkinsona commented 8 years ago

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.

snicoll commented 8 years ago

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.

snicoll commented 8 years ago

@wilkinsona can we go as far as doing this in 1.4.1 ?

wilkinsona commented 8 years ago

I think so. The current behaviour isn't useful and it's inconsistent with how the Gradle plugin behaves.

ltsallas commented 8 years ago

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

Setting to false in spring-boot-maven-plugin fixed both issues.

bclozel commented 8 years ago

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.

ltsallas commented 8 years ago

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.

CubeOfCheese commented 3 years ago

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'm happy to provide any other info. In the meantime, I'll just keep restarting the dev server Thank you

snicoll commented 3 years ago

@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.

CubeOfCheese commented 3 years ago

@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