Class ReloadingWicketFilter

  extended by org.apache.wicket.protocol.http.WicketFilter
      extended by org.apache.wicket.protocol.http.ReloadingWicketFilter
All Implemented Interfaces:

public class ReloadingWicketFilter
extends WicketFilter

Custom WicketFilter that reloads the web applications when classes are modified. In order to monitor changes to your own classes, subclass ReloadingWicketFilter and use include and exclude patterns using wildcards. And in web.xml, point to your custom ReloadingWicketFilter instead of the original WicketFilter.

The built-in patterns are:


Example. Defining custom patterns

 public class MyReloadingFilter extends ReloadingWicketFilter

NOTE. If you wish to reload, you have to make sure to include all classes that reference In particular, if it is referenced in, you will also have to include the latter. And this is viral, as for every class you include, you must check that all classes that reference it are also included.

It is also possible to add an extra URL to watch for changes using ReloadingClassLoader.addLocation() . By default, all the URLs returned by the parent class loader (ie all URL returned by ClassLoader.getResources(String) with empty String) are registered.

Important. It can be quite tricky to setup the reloading mechanism correctly. Here are the general guidelines:

Be sure to carefully read the following information if you also use Spring:

When using Spring, the application must not be a Spring bean itself, otherwise the reloading mechanism won't be able to reload the application. In particular, make sure not to use org.apache.wicket.spring.SpringWebApplicationFactory in web.xml. If you really need to inject dependencies in your application, use DefaultListableBeanFactory.autowireBeanProperties() in the init() method.

WARNING. Be careful that when using Spring or other component managers, you will get ClassCastException if a given class is loaded two times, one time by the normal classloader, and another time by the reloading classloader. You need to ensure that your Spring beans are properly excluded from the reloading class loader and that only the Wicket components are included. When getting a cryptic error with regard to class loading, class instantiation or class comparison, first disable the reloading class loader to rule out the possibility of a classloader conflict. Please keep in mind that two classes are equal if and only if they have the same name and are loaded in the same classloader. Same goes for errors like LinkageError: Class FooBar violates loader constraints, better be safe and disable the reloading feature.

Jean-Baptiste Quenot
See Also:

Field Summary
Fields inherited from class org.apache.wicket.protocol.http.WicketFilter
Constructor Summary
          Instantiate the reloading class loader
Method Summary
protected  ClassLoader getClassLoader()
 void init(javax.servlet.FilterConfig filterConfig)
          As per Filter.init(FilterConfig), is called by the web container to indicate to a filter that it is being placed into service.
Methods inherited from class org.apache.wicket.protocol.http.WicketFilter
createRequestContext, destroy, doFilter, doGet, getApplicationFactory, getFilterConfig, getFilterPath, getLastModified, getRelativePath, getWebApplication, isPortletContextAvailable, newWicketFilterPortletContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public ReloadingWicketFilter()
Instantiate the reloading class loader

Method Detail


protected ClassLoader getClassLoader()
getClassLoader in class WicketFilter
The class loader
See Also:


public void init(javax.servlet.FilterConfig filterConfig)
          throws javax.servlet.ServletException
Description copied from class: WicketFilter
As per Filter.init(FilterConfig), is called by the web container to indicate to a filter that it is being placed into service. WicketFilter.init(FilterConfig) goes through a series of steps of steps to initialise;
  1. Sets up ignore paths
  2. Records class loaders
  3. Finds the filter's path - WicketFilter.filterPath
  4. Sets up the IWebApplicationFactory and WebApplication for this filter, including it's initialisation.
  5. Initialise WebApplication request listeners.
  6. Log start of Application
  7. Detect if running in a Portlet context and if so intialise the WicketFilterPortletContext

Specified by:
init in interface javax.servlet.Filter
init in class WicketFilter
See Also:

Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.