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

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.

Related

Can't get Netbeans Project to acknowledge existing Tomcat or Glassfish Server

I haven't been able to figure out what I'm missing here.
I've installed Tomcat and can spin it up fine. (Glassfish too, in my efforts, but I had removed it when I took the screenshot.)
So now I want to hook my project up to the Tomcat instance so I can have Netbeans deploy it for me automatically.
I right-click on my project, go down to Properties. In Project Properties I select 'Run' and go to the drop down to select my server. Only, there's no servers.
Why is it not showing up here? Am I going about this all wrong?
Thanks in advance for any help!
Other potentially useful notes:
* Using Gradle (for my first time)
* Using Spring Boot (for my first time)
* On Windows 10 (don't hate me, I don't love it either)
I was chasing the wrong problem. Spring-boot provides an embedded server so I had no need to install and provide my own.
My real problem was that I had dependencies declared for jpa, postgresql, etc. that I hadn't configured in application.properties. When I tried to run, I'd get an error saying "a problem occurred starting process /path/to/my/jdk/java.exe". I couldn't figure what was going on and, looking around, I saw the issue mentioned in my question about the server.
The solution was to simply comment out the dependencies in my build.gradle until I was ready for them. After I got my PostgreSQL DB set up and added the configureation to application.properties, I was able to un-comment them and it's working great.

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.

Is it possible to use all camel components using HotSpot

I noticed that there are only a few camel extensions available to use in native mode. I am wondering if it's still possible to use the other camel components if you don't compile to native? And if, is it usefull to go that way, or should we for example stick to spring boot?
Note that all Camel extensions might not need a Quarkus one. Basically, a Quarkus extension is needed if we need to tune the Camel extension for GraalVM (add reflection declarations for instance). The interesting thing is that you can even do the work manually to make your Camel extension work in GraalVM mode and then report back so that we create a proper extension for all future use.
In JVM mode, all Camel extensions should work flawlessly. If you encounter an issue, please open a GitHub issue and we will take a look at it.
About if using Quarkus in JVM mode is worth it, I'm obviously partial but I think the Quarkus approach is beneficial even in JVM mode. You still have some of the benefits of better boot time and reduced memory usage. Obviously, depending on your application, they might not be important to you.

Flyway with spring boot overwrites whole DB every time I switch run mode between WAR and IDE run

I'm facing very weird issue while integrating flyway DB migration with spring boot application.
When I run the application from executable WAR using command line, it creates new DB at the start-up of application.
Now, If I switch the application run mode to IDE (i.e. run from STS), it again fires all the script from my db/migration folder. I can see the installed_on column time changes every-time I switch between these 2 run modes. I have tried enabling baselineOnMigrate property, but didn't get any effect of it.
Do you think its something related to spring boot embedded tomcat ? because at both run it creates individual tomcat which is embedded.
Please find my spring boot application.properties below:
mssql.dbname=issueDB
mssql.password=password
mssql.dbserver=localhost
mssql.port=1501
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://${mssql.dbserver}:${mssql.port};databaseName=${mssql.dbname}
spring.datasource.username=user
spring.datasource.password=${mssql.password}
spring.flyway.baselineOnMigrate=true
spring.flyway.locations=classpath:db/migration/testissue
spring.flyway.out-of-order=true
spring.flyway.baseline-version=1.3
spring.flyway.placeholder-prefix=$
spring.flyway.placeholder-suffix=$
spring.flyway.mixed=true
spring.flyway.cleanOnValidationError=true
I suppose, it could be caused by this property spring.flyway.cleanOnValidationError=true. According to the docs:
Whether to automatically call clean or not when a validation error occurs.
This is exclusively intended as a convenience for development. Even tough we strongly recommend not to change migration scripts once they have been checked into SCM and run, this provides a way of dealing with this case in a smooth manner. The database will be wiped clean automatically, ensuring that the next migration will bring you back to the state checked into SCM.
May be that you got some validation problems if you are running your application in different ways on the same database and flyway just clean your database and overwrite it with the current scripts state.

How to autostart org.eclipse.gemini.blueprint.extender in a feature based eclipse rcp application?

I have an eclipse rcp application that uses gemini blueprint. It has two features and hence a feature based product. Some of our bundles depend on service that where created by the blueprint extender. But actually the blueprint extender is only resolved on startup and not activated. Today we work around this by executing code in bundle activators, that checks if the org.eclipse.gemini.blueprint.extender bundle was started and if not it gets started.
Adding the bundle to the .product with a start level of 3 and autoStart=true has no effect. I think this is because our product is feature based. Is this correct? What is the best way to autostart the extender?
You need to edit configuration/config.ini file and add the bundle you want started to the osgi.bundles property. For example:
osgi.bundles=<existing entries>, org.eclipse.gemini.blueprint.extender#3:start
Have you tried to set the start level to 0 and auto start to true?
There is a suggestion in this link.May be it can help you.

Resources