Montag, 9. Juni 2014

Hot Reload Support with Spring Loaded and JHipster

Yesterday I dry to get hot development support for my Spring Boot example application. For this I first tried Spring Loaded. Spring Loaded is a Java agent that transforms classes at loadtime to support a better 'hot code replacement'. Spring Loaded supports the following types of code changes to replace hot at runtime: add, modify and delete methods, fields or constructors. To use the Spring Loaded Java agent download the agent JAR from the project page. Then add following Java VM arguments to run your Spring Boot application:
-javaagent:${project_loc:name}/springloaded-1.2.0.RELEASE.jar -noverify
In Eclipse e.g. you can use ${project_loc:..} variable to get the absolute path of your project.

JHipster reload Controller

Spring Loaded e.g. does not support to add new Controller Class at runtime. For this I add the JHipster loaded core to my project. JHipster it self is a Framework that is build on Maven, Spring and AngularJS. JHipster promises to support full hot reload of Java and JavaScript code. The realod support of JHipster is based on Spring Loaded. To use the JHipster add-on for 'hot code replacement' the Spring Loaded agent must be setup. To activate the JHipster add-on I add the following Java VM parameters to start my Spring Boot example application:
-javaagent:${project_loc:simpleweb-springboot}/build/springloaded/springloaded-1.2.0.RELEASE.jar -noverify 
-DhotReload.enabled=true
-DhotReload.watchdir[0]=${project_loc:simpleweb-springboot}/bin
-DhotReload.package.project=simpleblog
-DhotReload.package.domain=simpleblog.domain
-DhotReload.package.restdto=simpleblog.rest
In my Spring Boot application I add the following Conditional spring configuration for the JHipster reload support:
With the JHipster extension now I could add new controller or service classes at runtime. But there are also restrictions I could not change the base class or the interface which a class implements. For this I must restart my application.

You find my Spring Boot demo application with the hot reload support on GitHub. I only tried the Demo with Eclipse but it should also work in other environments.

1 Kommentar:

  1. I am gettin this error while reloading:
    JHipsterHandlerMappingListener : Failed to clean the urlMap and the handlerMethods objects

    AntwortenLöschen