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:
- Reload all changes to configuration. This stage will reload all Spring XMLs and find new
@Component/@Service/@Controllerannotated 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. - 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]










