From 461c200ce611666106a86e670076833bd3e0c706 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 24 Mar 2010 14:38:10 +0000 Subject: [PATCH] restricted onApplicationEvent callbacks for local ApplicationContext only (SPR-6964) --- .../web/servlet/FrameworkServlet.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/FrameworkServlet.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/FrameworkServlet.java index 6b7b00d311..fecd9899be 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/FrameworkServlet.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/FrameworkServlet.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,8 +93,7 @@ import org.springframework.web.util.WebUtils; * @see #setContextConfigLocation * @see #setNamespace */ -public abstract class FrameworkServlet extends HttpServletBean - implements ApplicationListener { +public abstract class FrameworkServlet extends HttpServletBean { /** * Suffix for WebApplicationContext namespaces. If a servlet of this class is @@ -437,7 +436,7 @@ public abstract class FrameworkServlet extends HttpServletBean wac.setServletConfig(getServletConfig()); wac.setNamespace(getNamespace()); wac.setConfigLocation(getContextConfigLocation()); - wac.addApplicationListener(new SourceFilteringListener(wac, this)); + wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener())); postProcessWebApplicationContext(wac); wac.refresh(); @@ -514,10 +513,8 @@ public abstract class FrameworkServlet extends HttpServletBean } /** - * ApplicationListener endpoint that receives events from this servlet's - * WebApplicationContext. - *

The default implementation calls {@link #onRefresh} in case of a - * {@link org.springframework.context.event.ContextRefreshedEvent}, + * Callback that receives refresh events from this servlet's WebApplicationContext. + *

The default implementation calls {@link #onRefresh}, * triggering a refresh of this servlet's context-dependent state. * @param event the incoming ApplicationContext event */ @@ -741,4 +738,16 @@ public abstract class FrameworkServlet extends HttpServletBean } } + + /** + * ApplicationListener endpoint that receives events from this servlet's WebApplicationContext + * only, delegating to onApplicationEvent on the FrameworkServlet instance. + */ + private class ContextRefreshListener implements ApplicationListener { + + public void onApplicationEvent(ContextRefreshedEvent event) { + FrameworkServlet.this.onApplicationEvent(event); + } + } + }