The latest expert opinions, articles, and guides for the Java professional.

Using Spring MVC with JRebel: Changing RequestMappings without restarting

According to a recent report, Spring MVC is used by 40% of Java developers out there, making it one of the most popular Java web frameworks in existence. Fair enough, it provides amazing benefits in providing a reliable, time-tested framework for developing web applications in Java. Developers don’t have to reinvent the wheel when it comes to well-understood problems, like serving content over HTTP and wiring up a model-view-controller (MVC) layout for their application.

If you take a look on Stackoverflow, a common task for developers using Spring MVC is to wire new RequestMappings for their controllers.

In Spring, a RequestMapping can be defined as an annotation like this:

public ModelMap petsHandler() {	 
    return new ModelMap("petList",;

Which will look for a pets.jsp underneath the src/main/webapp/WEB-INF/jsp folder. This is the base use case for RequestMappings, it may not change very often in a mature application, but will change often during the initial development phase of an app. RequestMappings very often can contain path variables like this:

public ModelAndView ownerHandler(@PathVariable("ownerId") int ownerId) {
    ModelAndView mav = new ModelAndView("owners/show");
    return mav;

In this use case, {ownerId} is a path variable that can be referenced in the code and could change often during development.

Spring is good because it enables developers to write less original code to accomplish normal, everyday tasks. But, it does have a long initialization sequence which means that every redeploy or restart of your application server will take even longer than it already does–which is annoying enough already.

No fear though, JRebel works great with Spring and over 80 other popular Java frameworks and extensions. JRebel enables developers to make almost any Java code change without rebuilding, redeploying, or restarting. JRebel replaces code in the running JVM, so developers can view code changes instantly.

Let’s say we want to change the RequestMapping from /pets to /allPets, with JRebel, that’s no problem. We can even rename the pets.jsp file to allPets.jsp and then the mapping will be fully functional.

Our controller now looks like this:

public ModelMap petsHandler() {	 
    return new ModelMap("petList",;

Before the change:
Screenshot 2014-08-20 10.56.06

After making the change, we see JRebel reloaded the class and reconfigured the Spring bean:

2014-08-20 10:56:31 JRebel: Reloading class 'org.springframework.samples.petclinic.web.ClinicController'.
2014-08-20 10:56:31 JRebel: Reconfiguring bean 'clinicController' [org.springframework.samples.petclinic.web.ClinicController]

We can see it works, without a redeploy of the application or restart of the app server:

Screenshot 2014-08-20 10.56.40

Thanks to JRebel, our developer avoided the entire build, redeploy, restart cycle and was able to successfully change the RequestMapping for our application and can move on to their next task more quickly.



Responses (3)

  1. Avatar  


    August 28, 2014 @ 1:53 pm

    Wow, never thought JRebel could do that.

  2. Avatar  

    Krishna Kiran

    August 19, 2015 @ 6:50 pm

    it doesnot work for us and infact makes the application very slow. We are trying to update the request mapping, but it never worked

  3. Avatar  

    Adam Koblentz

    August 25, 2015 @ 2:25 pm

    Hi Krishna, have you contacted our support team? If not, please email and make sure to include your jrebel.log file.


RSS feed for comments on this post.

Leave a comment