Updated Branches: refs/heads/wicket-1.5.x ee7447c86 -> 4c43c2eac
WICKET-4872 set contextClassLoader before creating application; destroy application before initializing the new one Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/4c43c2ea Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/4c43c2ea Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/4c43c2ea Branch: refs/heads/wicket-1.5.x Commit: 4c43c2eac2cb686f40b1f209dcda49e6e7530c44 Parents: ee7447c Author: svenmeier <[email protected]> Authored: Wed Nov 21 23:39:43 2012 +0100 Committer: svenmeier <[email protected]> Committed: Wed Nov 21 23:39:43 2012 +0100 ---------------------------------------------------------------------- .../protocol/http/ReloadingWicketFilter.java | 10 +- .../apache/wicket/protocol/http/WicketFilter.java | 82 ++++++++------- 2 files changed, 48 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/4c43c2ea/wicket-core/src/main/java/org/apache/wicket/protocol/http/ReloadingWicketFilter.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/ReloadingWicketFilter.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/ReloadingWicketFilter.java index def56f3..fd91cd1 100644 --- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/ReloadingWicketFilter.java +++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/ReloadingWicketFilter.java @@ -96,11 +96,9 @@ import org.apache.wicket.util.listener.IChangeListener; * </p> * * <p> - * 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 <b>not</b> 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. + * When using org.apache.wicket.spring.SpringWebApplicationFactory, the application must be a bean + * with "prototype" scope and the "applicationBean" init parameter must be explicitly set, otherwise + * the reloading mechanism won't be able to recreate the application. * </p> * * <p> @@ -153,6 +151,8 @@ public class ReloadingWicketFilter extends WicketFilter { public void onChange() { + destroy(); + // Remove the ModificationWatcher from the current reloading class loader reloadingClassLoader.destroy(); http://git-wip-us.apache.org/repos/asf/wicket/blob/4c43c2ea/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java index cbb7e9d..3a3dc04 100644 --- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java +++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java @@ -330,59 +330,63 @@ public class WicketFilter implements Filter this.isServlet = isServlet; initIgnorePaths(filterConfig); - // locate application instance unless it was already specified during construction - if (application == null) + final ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader newClassLoader = getClassLoader(); + try { - applicationFactory = getApplicationFactory(); - application = applicationFactory.createApplication(this); - } - - application.setName(filterConfig.getFilterName()); - application.setWicketFilter(this); + if (previousClassLoader != newClassLoader) + { + Thread.currentThread().setContextClassLoader(newClassLoader); + } - // Allow the filterPath to be preset via setFilterPath() - if (filterPath == null) - { - filterPath = getFilterPathFromConfig(filterConfig); - } + // locate application instance unless it was already specified during construction + if (application == null) + { + applicationFactory = getApplicationFactory(); + application = applicationFactory.createApplication(this); + } - if (filterPath == null) - { - filterPath = getFilterPathFromWebXml(isServlet, filterConfig); - } + application.setName(filterConfig.getFilterName()); + application.setWicketFilter(this); - if (filterPath == null) - { - filterPath = getFilterPathFromAnnotation(isServlet); - } + // Allow the filterPath to be preset via setFilterPath() + if (filterPath == null) + { + filterPath = getFilterPathFromConfig(filterConfig); + } - if (filterPath == null) - { - log.warn("Unable to determine filter path from filter init-parm, web.xml, " - + "or servlet 3.0 annotations. Assuming user will set filter path " - + "manually by calling setFilterPath(String)"); - } + if (filterPath == null) + { + filterPath = getFilterPathFromWebXml(isServlet, filterConfig); + } - final ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader(); - final ClassLoader newClassLoader = getClassLoader(); + if (filterPath == null) + { + filterPath = getFilterPathFromAnnotation(isServlet); + } - ThreadContext.setApplication(application); - try - { - if (previousClassLoader != newClassLoader) + if (filterPath == null) { - Thread.currentThread().setContextClassLoader(newClassLoader); + log.warn("Unable to determine filter path from filter init-parm, web.xml, " + + "or servlet 3.0 annotations. Assuming user will set filter path " + + "manually by calling setFilterPath(String)"); } - application.initApplication(); + ThreadContext.setApplication(application); + try + { + application.initApplication(); - // Give the application the option to log that it is started - application.logStarted(); + // Give the application the option to log that it is started + application.logStarted(); + } + finally + { + ThreadContext.detach(); + } } finally { - ThreadContext.detach(); - if (newClassLoader != previousClassLoader) { Thread.currentThread().setContextClassLoader(previousClassLoader);
