JRebel Tutorial: Using JRebel Spring Integration

JRebel Spring plugin takes advantage of JRebel 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 JRebel 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/@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.

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

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, JRebel!”. After you save and access /hello2.do in the browser you will see the message “Hello, JRebel!” as well as the following lines printed in the console: