smeeb
smeeb

Reputation: 29477

Spring Boot Devtools by Example

According to the Spring Boot Devtools docs, devtools won't run in "production mode"; that is, if you execute your Spring Boot app with java -jar .., then it won't use devtools' built-in JVM magic. However, the Spring Boot starter docs only show you one way of running your Spring Boot application...via java -jar....

So first I'm wondering: How do I run my Spring Boot app in non-production mode? I know you can run your app with Spring Boot CLI (e.g. spring run), but is that the only way?

Also, the same devtools docs mention you can explicitly remove the devtools jar from your production binary by using some excludeDevtools option, but they never explain where/how to use this. Any examples/ideas here?

Upvotes: 12

Views: 7757

Answers (2)

rajadilipkolli
rajadilipkolli

Reputation: 3601

To start with Spring boot and devtools made development easier. Spring boot uses embedded servlet container ( tomcat,undertow,jetty) with this you can have production ready code even in non-production environment.

Coming to your question how to run Spring-boot application in non-production environments, we can run application directly from Spring tool suite IDE by right click -> run as Spring boot if it is local environment.

If the build tool used is maven then from command prompt mvn boot:run , if it is gradle then gradle bootRun from root folder of project location in command prompt. If you are packing your application as uber jar then Java -jar .., also if your environment is Linux you can start as a process.

Regarding ignoring devtools in production environment, Spring boot intelligently ignore devtools jar if we specify Spring-boot-devtools as optional scope in dependencies of your build tool(maven, gradle) . In gradle Spring boot gradle plugin takes care of ignoring devtools for final deployed jar or war

Update :: To debug a Spring Boot application run with Gradle, as seen at http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-remote-debug-gradle-run596

Add this to your build.gradle file:

applicationDefaultJvmArgs = [

"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005" ]

In IntelliJ Idea IDE or STS, setup a new Debug configuration and in the options select "Remote". The defaults should be fine, but pay attention to the port number and transport type ("socket"). Have fun!

Upvotes: 1

Marius Bogoevici
Marius Bogoevici

Reputation: 2400

1) One example of running a Spring Boot app in non-production mode (i.e. not from the JAR) is from an IDE (most specifically Eclipse or IntelliJ), where you can launch the application from the main method, or using the Spring Boot launch support. This is the most practical use of Dev Tools as it allows to continuously watch the changes in your application without restarting.

2) excludeDevTools is an option of the Spring Boot Maven Plugin http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/maven-plugin/repackage-mojo.html or the Gradle plugin - see http://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html#build-tool-plugins-gradle-repackage-configuration.

So in your case it would be bootRepackage { mainClass = 'demo.Application' excludeDevtools = true }

Upvotes: 9

Related Questions