Integrating JavaRebel with Spring
Wednesday, March 12th, 2008We have started working on integrating JavaRebel with the Spring Framework. First we are concentrating on annotation based configuration and then see what can we do with changes in the XML configuration files.
JavaRebel detects added/removed/changed annotations so reloading the changes is a matter of finding the right spots in the code that test for existence of certain classes and their annotations. The simplest solution on failure is to just refresh the context and try one more time. If it fails anyway the extra time relooking is not expensive.
Lets take an example. We are using the Petclinic sample that comes with Spring. Lets add a new controller.
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class NewController {
public NewController() {}
@RequestMapping(“/newWelcome.do”)
public void welcomeHandler() {}
}
And create a newWelcome.jsp also. Lets try to visit the url petClinic/newWelcome.do now. Of course we get an 404. Lets look at the code in DispatcherServlet that looks for the mappings.
while (it.hasNext()) {
// looking for the handler
…..
return handler;
}
return null;
Lets make this code refresh the application context if null is returned and after the refresh try one more time.
((AbstractRefreshableApplicationContext)getWebApplicationContext()).refresh();
// look for the handler again
// …
}
What does it give us? Adding/changing new controllers is a matter of refreshing the context. Basically all integrations boil down to reiniting some internal state to take into account the changes.
On error we are falling back to give it one more try. Actually this example will find the newly added controller without JavaRebel because the refresh of the context will scan for the new class files. Of course all the other adding/changing/removing classes/methods/annotations etc. will need on-the-fly class reloading.
The status of integrating JavaRebel with different projects can be seen from our Google Code page. If you need help with your own integration just use the forum or drop us a line at support email.


