What can i do to not re-run gradle spring boot application again and again - spring

I've one gradle spring boot project. Even if i'd to put one log at some place. It requires re-run of the application. Is there anyway to add these type of changes on the fly when application is running (on my local system).

For some cases, hot reload which is JVM feature should do the trick

Related

Debug Spring Boot 3 in IntelliJ Community

Since the migration to Spring Boot 3 my application doesn't hold at breakpoints any more, when I run the Maven Spring Boot goal mvn spring-boot:run.
This is because Spring forks the thread or the process and the debugger is not attached to this.
In former Spring-Boot versions you could disable forking by passing -Dspring-boot.run.fork=false (see How to debug spring-boot application with IntelliJ IDEA community Edition?).
Unfortunatly this option was removed as you can read in the Spring Boot 3.0 Migration Guide:
The fork attribute of spring-boot:run and spring-boot:start that was deprecated in Spring Boot 2.7 has been removed.
Is there any possibility to make breakpoints work again?
Ideas so far
Of course IntelliJ Ultimate has better Spring Boot integration. I'm trying to make it work with the Community Edition.
I also tried not to run the Maven goal but to make an Application run configuration. This failed so far, because of java.lang.ClassNotFoundException, it doesn't find the Main class. Not sure if I should investigate that option further.
Last idea was to start the Maven goal with debug options such that an external debugger can attach. That didn't work either and even if it would, I could only attach the debuger after startup with would make debugging the creation of spring context impossible.

Does every spring boot application create a tomcat container to be able to run?

For example,
I understand adding specific dependencies like spring-boot-starter-web that contains tomcat as transitive dependency triggers the spring framework to initialize tomcat container but I want to know if we say a spring-boot application is running, does it imply always that tomcat is also running?
I want to know if we say a spring-boot application is running, does it imply always that tomcat is also running?
No, it doesn't.
Spring boot can be used for both web applications and non-web applications.
For web applications you can use tomcat/jetty/undertow/netty for example, its up to you to chose what works for you the best.
If you don't want to run an embedded version of the web server you can opt for creating a WAR file and place it into the web server prepared in-advance.
If you don't want to run web application at all (something that is built around "Request - Response" way of work in the most broad sense) - you can create a "CommandLineRunner" - in this case you don't need to depend on neither web-mvc nor webflux. For more information about Command Line Runners read here for example
You can have an embedded server in your JAR that is able to be run on its own. By default it is Tomcat but you can change this to others, like Jetty. Additional details:
https://docs.spring.io/spring-boot/docs/2.0.6.RELEASE/reference/html/howto-embedded-web-servers.html
If you don't want to have an embedded server and you want to deploy your application you can also create WAR files instead of JAR files. Additional details:
https://www.baeldung.com/spring-boot-no-web-server
https://spring.io/guides/gs/convert-jar-to-war/

Debugging not working for Spring Boot 2.2 and IntelliJ Idea

By running the app in debugging mode (spring-boot:run) with IntelliJ Idea CE, no breakpoints work at all when using Spring Boot 2.2. Instead, when rolling back to Spring Boot 2.1.1, everything works fine. What am I doing wrong? Is there an option/flag to add for 2.2 to make the debugger work?
I would recommend running the app directly from the IDE rather than using mvn spring-boot:run. Doing so will give you the best experience in the IDE.
The release notes indicate that the Spring Boot Maven Plugin now forks the process by default which is the reason why you can't debug the application as you used to with 2.1. If you really have to run the app using the maven plugin, you can disable forking the process (e.g. using -Dspring-boot.run.fork=false)
Edit Configuration -> Application -> in Main Class: select your Main class (the one that contain your main method(public static void main) ) and run

Spring Boot Maven plugin - spring-boot:run and production

Is it a good idea or practice to start a Spring Boot application at production with a following command of Spring Boot Maven plugin ?
mvn spring-boot:run
No, this is a bad idea.
You would re-build your project on every run which means that you would pull all needed dependencies on each new VM / container.
Also using the spring-boot-maven-plugin in conjunction with the dev-tools for example would lead to options that you don't want in production.
This ranges from using other database settings to disabled caching mechanisms for your templating engine.
Use the executable jar instead.
If you want to run the application with the Maven JVM this is fine.
It is just an alternative way to run your application instead of using the executable jar.
As an alternative you could also start your application with gradle
gradle bootRun
Which is best depends on your circumstance. For live production code I would use a versioned executable jar always.

Spring Boot and Continuous Delivery simple pipeline

I can't find any example or article how can the continuous delivery pipeline look like when we are using Spring Boot + Jenkins.
In Java EE I usually do it like this:
Push changes to repository
Jenkins checks for changes every 5 minutes
if there was a change, Jenkins pulls the sources and run maven build
using wildfly maven plugin I run redeploy on server
And generally I wonder what to do in last point when I'm using Spring Boot. Application is packaged into single JAR and run in separate process so in Spring Boot there is actually no such thing like redeploy. Do I have to write some script to kill old process first and then run the new artifact? Or maybe there is something like "spring boot cli" where I could manage all running spring boot apps?
You need to kill old process and run new process as a service.
It is all very well explained here Spring Boot application as a Service.
There is nice ssh plugin for jenkins that we use : https://wiki.jenkins-ci.org/display/JENKINS/Publish+Over+SSH+Plugin
Copy jar to the server
Stop old service
Run new service
EDIT : Added Spring boot reference for running spring boot as a service - http://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html #Vaelyr

Resources