5

In my appllicaiton, I add SpringBoot devtools to improve the development speed.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
</dependency>

In its official document, it says

Developer tools are automatically disabled when running a fully packaged application. If your application is launched from java -jar or if it is started from a special classloader, then it is considered a “production application”.

The application is launched from java -jar in Production. But how is it lanched in Intellij idea while in development?

Robin Sun
  • 1,352
  • 3
  • 20
  • 45

1 Answers1

8

It's actually quite simple, but not obvious. When spring-boot-devtools is included on the classpath, then devtools is enabled.

By default the spring-boot-maven-plugin excludes spring-boot-devtools when building the final jar file, therefore it is disabled.

Spring Boot Maven Plugin docs:

Devtools is automatically excluded by default (you can control that using the excludeDevtools property). In order to make that work with war packaging, the spring-boot-devtools dependency must be set as optional or with the provided scope.

If you run your spring application from your IDE or run mvn spring-boot:run spring-boot-devtools is in your classpath.

When spring-boot-devtools is running you will get a log similar to this:

.e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
rjdkolb
  • 10,377
  • 11
  • 69
  • 89
  • If I run spring application from IDE, is it using java -jar under the hood? – Robin Sun Jan 08 '19 at 09:02
  • From your IDE it does not use java -jar on the final JAR file built by the spring-boot-maven plugin. Like Boris the Spider says, it runs in exploded mode. – rjdkolb Jan 08 '19 at 09:47