Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Dev Tools Turning them off for production?

I was reading around a lot about spring dev tools and I have tried them on and they seem pretty cool. However, I don't understand how they get enabled / disabled. For instance just adding the dependency, everything magically works, but what if I wanted to deploy my code to production? Are the dev tools still running and I need to disable them with a profile or something?

like image 797
Matthew Fontana Avatar asked Jun 08 '16 11:06

Matthew Fontana


People also ask

How do I disable Devtools in spring boot production deployments?

No, it's turned off automatically. From the Spring Boot reference documentation: Developer tools are automatically disabled when running a fully packaged application. If your application is launched using java -jar or if it's started using a special classloader, then it is considered a “production application”.

Is Devtools enabled in the production environment by default?

Dev tools module can customize this capability by setting few properties. By default, the caching feature is disabled. We can enable it to use in production environment by setting a property. There are many such UI template libraries that support this feature.

How Devtools can be enabled?

To include devtools support, simply add the module dependency to your build: Maven. Gradle. Developer tools are automatically disabled when running a fully packaged application.

How does Devtools spring boot work?

spring-boot-devtools module includes an embedded LiveReload server that is used to trigger a browser refresh when a resource is changed. For this to happen in the browser we need to install the LiveReload plugin one such implementation is Remote Live Reload for Chrome.


3 Answers

No, it's turned off automatically.

From the Spring Boot reference documentation:

Developer tools are automatically disabled when running a fully packaged application. If your application is launched using java -jar or if it’s started using a special classloader, then it is considered a “production application”. Flagging the dependency as optional is a best practice that prevents devtools from being transitively applied to other modules using your project. Gradle does not support optional dependencies out-of-the-box so you may want to have a look to the propdeps-plugin in the meantime.

and

If you want to ensure that devtools is never included in a production build, you can use the excludeDevtools build property to completely remove the JAR. The property is supported with both the Maven and Gradle plugins.

like image 180
Brian Clozel Avatar answered Oct 18 '22 04:10

Brian Clozel


It is excluded automatically for Spring Boot applications that use the JAR packaging. However, for WAR packaged Spring Boot projects, it is not. For Maven Spring Boot projects you must mark the dependency as provided and also set excludeDevTools=true in your pom.xml.

Change devtools to "provided"

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>provided</scope>
</dependency>

Exclude devtools from maven spring build plugin

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <excludeDevtools>true</excludeDevtools>
    </configuration>
</plugin>

More information here: https://github.com/spring-projects/spring-boot/issues/7556

like image 39
Burton Avatar answered Oct 18 '22 03:10

Burton


spring-boot-devtools is only for easing development effort. While packaging the application this dependency is not included. Cannot be used to create a shippable product.

like image 1
Ray Avatar answered Oct 18 '22 04:10

Ray