Table of contents

Installation

To install the JavaRebel Spring plugin you need to put javarebel-spring-plugin.jar in the classpath next to the Spring JARs. E.g. in a web application if the Spring JARs are in WEB-INF/lib you should put the javarebel-spring-plugin.jar in WEB-INF/lib. JavaRebel will then discover and activate the Spring plugin at runtime and print the following lines in the console:

JavaRebel: Found plugin: /path/to/javarebel-spring-plugin.jar

Using JavaRebel Spring Plugin

JavaRebel Spring plugin takes advantage of JavaRebel class reloading to reload Spring dependencies. It supports registering new Spring beans, adding/removing dependencies and adding new MVC controllers and handler methods. These can be done using either XML configuration or annotations. The minimal supported Spring version is 2.0.x.

To use the JavaRebel Spring plugin it helps to understand that it will work in two stages:

  1. Reload all changes to configuration. This stage will reload all Spring XMLs and find new @Component/@Service/@Controller annotated beans. It will not have any effect on existing beans, but all beans created after that will be configured according to the newly loaded metadata.
  2. Call AutowireCapableBeanFactory.configureBean() on all singletons that had code changes in this session. This will reinject all configured field or method dependencies on those singletons.

Such two-staged process is important since reloading configuration changes is cheap while reinjecting bean dependencies may create or reinitialize beans and is expensive.

Example: Adding a new dependency via XML

You have a configuration file applicationContext.xml and a configured bean myBean for class MyBean. You add a new setter method

public void setMyProperty(String property) {
  System.out.println(property);
}

to MyBean and add <property name="myProperty" value="Success!"/> to the myBean configuration. After you save and access your application the following lines will be printed in the console:

JavaRebel: Reloading class 'MyClass'
JavaRebel-Spring: Reloading Spring bean definitions in 'applicationContext.xml'.
JavaRebel-Spring: Reconfiguring bean 'myBean' [MyClass]
Success!

Example: Adding a new dependency via annotations

You have a configured singleton bean MyBean with the @Service annotation. You create a new class AnotherBean annotated with @Component:

@Component
public class AnotherBean {
  public void success() {
    System.out.println("Success!");
  }
}

You also add the following setter method to MyBean class:

@Autowired
public void setAnotherBean(AnotherBean ab) {
  ab.success();
}

After you save and access your application the following lines will be printed in the console:

JavaRebel: Reloading class 'MyClass'
JavaRebel-Spring: Reconfiguring bean 'MyBean' [MyBean]
Success!

Example: Adding a controller and handler via annotations

You have a configured Spring MVC web application. You create a new controller class MyController with the handler method myHandler():

@Controller
public class MyController {
  @RequestMapping("/hello.do")
  public void myHandler() {
  }
}

You also create a hello.jsp with the following content:

<html>
<body>
Hello, Spring!
</body>
</html>

After you save and access /hello.do in the browser you can see “Hello, Spring!” message.

Now you can also add a second handler method myHandler2() and bind it to /hello2.do. You also need to create a hello2.jsp with the message “Hello, JavaRebel!”. After you save and access /hello2.do in the browser you will see the message “Hello, JavaRebel!” as well as the following lines printed in the console:

JavaRebel: Reloading class 'MyController'
JavaRebel-Spring: Reconfiguring bean 'MyController' [MyController]

Online examples

Our Customers Say

“For the price, and for how easy it is to get installed and running in a developers’ environment, using JRebel is pretty close to a no-brainer.”

Jim Lesko, GT Nexus

Recent Tweets

RT @djspiewak: JRebel is my most valuable productivity-boosting tool by a *wide* margin. Anyone doing server-side development needs it! 2 days ago

RT @davetownsend: i may have said this before but #jrebel just frigging rules for developing #spring apps. FTW! 4 days ago

5 Article Series on Reloading Java Classes http://www.theserverside.com/news/thread.tss?thread_id=59657 6 days ago

Olark Livehelp