IntelliJ always restarting/closing Spring root on class reload - spring

I'm using Spring and Tomcat, it worked before fine but now, on each add that should be hot swappable it just restarts the server.
Something easy just as adding System.out.println("Something") into a method, if I press update classes and resources, it says 1 class reloaded and starts to restart the server for some reason. How to solve this issue?

Related

Intellij Hot Reload doesn't work properly after reload it is unable to find the spring injected bean

I am working with a spring boot project in intelliJ and seems like hot reloading is not working as expected. I have configured the project and IDE so that hot reload should work i.e i have checked build project automatically under settings also in registry i have checked compiler.automake.allow.when.app.runing and have added spring boot dev-tools dependency and with these steps intelliJ does hot reload when i change my source code, But i don't see much difference in productivity by saying, that I mean a simple restart server and hot reload is almost working same, also many of the times when hot reload takes place i get bean dependency resolve error
`Field courseRepository in com.practice.jpamappings.JpaMappingsApplication required a bean of type 'com.practice.jpamappings.repositories.CourseRepository' that could not be found`.
I have checked with the error and it's not related to the missing bean cause when i restart the server everything works fine so does hot reload have to do something with this missing bean error ?
did i configure the hot reload properly ? or i need to do some more efforts to make it work properly.

can spring auto reload changes like grails?

One of the main benefits of grails, which is based on Spring, is that you dont need to rebuild and re-run the entire application (which takes minutes) each time you change a line of code, it just recopiles that one file and auto-loads the changes.
Following this tutorial:
https://spring.io/guides/gs/spring-boot/
To run the app, you have to use the command line and do this outside of intellij:
./gradlew build && java -jar build/libs/gs-spring-boot-0.1.0.jar
If you change a line of code, e.g. in a controller, you have to kill the application, rebuild it and restart it, which takes a while.
I came across something called automatic restart in dev tools. Is this something to do with auto-reloading of changes, and if so, how is it used?
If a class is changed , I am sorry that Spring boot devtools will not just reload that changed classes but it will restart the whole application automatically . But this restart should be faster than the normal cold start based on what the docs said :
The restart technology provided by Spring Boot works by using two
classloaders. Classes that do not change (for example, those from
third-party jars) are loaded into a base classloader. Classes that you
are actively developing are loaded into a restart classloader. When
the application is restarted, the restart classloader is thrown away
and a new one is created. This approach means that application
restarts are typically much faster than “cold starts”, since the base
classloader is already available and populated.
If you need to just reload the changed classes , you may consider to use JRebel which is not free.
To use spring boot devtools , just includes its dependency and then start the application as usual using IDE.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
It will the monitor the classpath folders and then restart the application if there are any changes in these folders.
In case of Eclipse , what you need is to ensure Project ➡️ Build Automatically is selected. Once the source codes are changed , Eclipse will then just compiled that changed sources codes to the classes in the classpath folders automatically which trigger devtools to restart the application.
Based on the #Ken Chan answer but very briefly
For Eclipse - click in the menu "Project" -> select "Build Automatically"
In my case I was running some spring boot server - I had to stop the server, enable "Build Automatically" like on the picture, then start the server again and on every change - the code recompiled.

How can I reload my changes on Spring Boot without having to restart my server?

I use spring boot 2.0.0 with netbeans 8.2 and gradle.
I use
compile('org.springframework.boot:spring-boot-devtools')
How to avoid to restart every time server when i do a change in the code ?
Are you looking to reload the changes still?
If so you would need to look at another technology like JRebel which can reload without a restart.
https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html#using-boot-devtools-restart
However, for just disabling the restart ,
spring.devtools.restart.enabled=false can be set within a properties file. There is a gotcha to disable it completely which requires a system property set, documented here
https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html#using-boot-devtools-restart-disable
I think the only solution is JRebel, but it's not free.
Using dev-tools will make your restart faster and automatic, but will not eliminate it. In my Spring Boot/AngularJS projects I use dev-tools + LiveReload (to reload HTML/JavaScript files dynamically) and I'm quite satisfied.

Spring-Boot Vaadin deploy project on jetty

How to deploy a Spring boot vaadin project on jetty using intellij, the Idea behind that is to refresh the project after each changes without restarting the server.
I don't really understand the people who downvote a question without answering it. however here is the answer:
in Spring framework using spring-dev-tools, you have the option to deploy the project whenever the class path changes( in intellij the class path change event is triggered when we rebuild the project, in eclipse class path change event is triggered as soon as we hit the save file of any class). Server will restart (tomcat or jetty) and load the project (Restart method).
we could overcome this expensive approach using third party plug-ins such as JRebel. JRebel will only deploy the class that has been changed.
consider developing a web app and consider making about 100 runs a day, everytime the server restarts it consumes 3 seconds. do the math

How to debug a Spring Boot Web Application in STS?

I am new to the Spring Framework and so I started with the Spring Boot projects.
In particular, I took the https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-secure-jdbc project and modified the pom.xml so that it becomes self contained (replaced spring-boot-samples with spring-boot-starter-parent in the parent->artifactId tag, removed properties node, added in repositories and pluginRepositories from http://docs.spring.io/spring-boot/docs/1.2.2.BUILD-SNAPSHOT/reference/htmlsingle/#getting-started-maven-installation).
I successfully built and ran this application outside of STS first with 'mvn spring-boot:run', then imported the Maven project into STS and it builds and runs there successfully.
I am able debug this application by right-clicking on the project folder and choosing Run->Debug As ...->Spring Boot App and the debugger does stop at the breakpoints I've set in the ApplicationSecurity class methods. However, the browser window does not automatically pop-up in STS nor the system browser (which I expect - is this correct?).
When I browse to localhost (port 8080) using the 'Internal Web Browser' within STS/Eclipse the HTML pages render out but the breakpoints that I've set in the #RequestMapping("/") methods do not get hit (I suspect that this is probably due to the fact that the browser is in a separate process to the debugger).
So, how do I debug #RequestMapping methods within STS - this would help me to understand the Spring framework better.
I have limited knowledge of Eclipse/STS, so could there be a problem with my installation?
You don't need to use the embedded browser to debug a server (the browser is a separate process). If your #RequestMapping breakpoints are not hit then I suspect Spring didn't dispatch to those routes for whatever reason (maybe security?).

Resources