[
https://issues.apache.org/jira/browse/CXF-4127?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13213571#comment-13213571
]
Jens Borgland commented on CXF-4127:
------------------------------------
Note that {{org.springframework.context.support.AbstractApplicationContext}}
recreates its {{ApplicationEventMulticaster}} when the context is refreshed.
The CXFServlet therefore needs to add itself to the set of statically specified
application listeners instead.
{code:title=registering a listener|borderStyle=solid}
WebApplicationContext wac =
WebApplicationContextUtils.getWebApplicationContext(getServletContext());
GenericApplicationListenerAdapter listener = new
GenericApplicationListenerAdapter(this);
// This won't work:
//((ConfigurableWebApplicationContext) wac).addApplicationListener(listener);
// This works:
((AbstractApplicationContext) wac).getApplicationListeners().add(listener);
{code}
> CXFServlet should be reinitialized on ContextRefreshedEvent
> -----------------------------------------------------------
>
> Key: CXF-4127
> URL: https://issues.apache.org/jira/browse/CXF-4127
> Project: CXF
> Issue Type: Bug
> Affects Versions: 2.4.7, 2.5.3
> Reporter: Jens Borgland
>
> I have a web application that uses Spring and CXF and is deployed on Tomcat.
> The application is initialized using the
> {{org.springframework.web.context.ContextLoaderListener}}.
> With the fix for CXF-4094 I am now able to refresh the Spring context (like
> described below) without any exceptions but since the {{CXFServlet}} isn't
> created by Spring and doesn't listen for {{ContextRefreshedEvent}}, the
> {{Bus}} and the {{DestinationRegistry}} doesn't get reinitialized.
> I refresh the Spring context like this:
> {{((ConfigurableApplicationContext)applicationContext).refresh();}}
> I think the CXFServlet should implement
> {{ApplicationListener<ContextRefreshedEvent>}} and register itself as an
> application listener on the Spring context and reinitialize itself in the
> {{onApplicationEvent}} method.
> As an experiment I created a subclass to CXFServlet with the implementation
> of onApplicationEvent below (which seems to work). The real implementation
> could perhaps do a bit less work.
> {code:title=RefreshingCXFServlet.java|borderStyle=solid}
> @Override
> public void onApplicationEvent(ContextRefreshedEvent event) {
> destroy();
> setBus(null);
> try {
> super.init(m_sc);
> } catch (ServletException e) {
> throw new RuntimeException("Unable to reinitialize the CXFServlet", e);
> }
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira