Intellij IDEA: apply changes in Spring-Boot project without restart

If you work with scripting languages and frameworks, you don't need to recompile your application code to apply changes. For Java, it's not the case. Fortunately we can make it more convenient using Intellij IDEA's capabilities. Having set a couple of options in your IDE, you will be able to apply changes in your code without project restart. Let's take a look at practical example.

Let's say you have a Spring project https://github.com/spring-guides/gs-rest-service.git. If you execute main() method and navigate to http://localhost:8080/greeting in your browser, you will see JSON response

 {"id":1,"content":"Hello, World!"}

If we change controller from

 Greeting greeting(@RequestParam(value="name", defaultValue="World") String name)

To the

 Greeting greeting(@RequestParam(value="name", defaultValue="Beautiful World") String name)

and check the response in the browser -- nothing is changed because the java code is not recompiled. Let's make it apply changes without restart. For this we need to tweak a couple of settings in IDEA. Go to Help > Find Actions menu (or use Ctrl+Shift+A shortcut) and type "Registry". Then select found action and tick "compiler.automake.allow.when.app.running" option in opened dialog


One more step is to navigate to Settings > Build, Execution, Deployment > Compiler and tick option "Build project automatically".


Now you can change REST controller's default value to something else. When you open the browser and refresh a page, result will be visible without restarting project, i.e. changes will be applied on the fly. I hope this Intellij IDEA setup will save you some precious time and make your development process more pleasant.  

Comments