cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Kulp <>
Subject Re: do i need ContextLoaderListener?
Date Wed, 14 May 2008 15:27:42 GMT

On May 14, 2008, at 10:57 AM, Eoghan Glynn wrote:
> Its also worth noting that you should use the spring context loader  
> listener approach if one of your beans has a dependency on the "cxf"  
> Bus bean (for example takes a reference to this bean via a property).
> AFAIK it may lead to some confusing side-effects if you take the  
> simpler approach of defining a cxf-servlet.xml and pulling in  
> everything by default.

Right, this is the full symptom of my comment about "since cxf- 
servlet.xml is processed in a child context, some things don't get  
injected quite the same as the definitions in the parent context  
aren't available in the subcontext".    Basically, definitions by name/ 
id from the parent context are not available when processing the child  
context.   You can probably get around the "Bus" issue by creating a  
spring bean definition for a bus that calls the  
"BusFactory.getThreadDefaultBus()" for the factory method to grab the  
Bus that was created from the first part, but pretty much anything  
else that may be needed inthe parent context aren't available either.

Still, it's not ideal (actually, a little sucky) and I'd definitely  
recommend the context listener approach unless the needs are very  
simplistic.  Most pure jaxws things with no CXF specific stuff would  
qualify.   FYI: the JAX-WS TCK setup we currently use uses the non- 
context listener approach which is why I'm pretty sure most "pure  
jaxws" things can work that way.

That said, one of the "problems" with the context-listener approach is  
that we don't document (very well) the full list of stuff that can be  
imported.   For example, if you need ws-addressing or ws-rm, you need  
to import those cxf-extension things, but I'm not sure how well that's  
documented.   With 2.0.6/2.1, we do have a cxf-all.xml (in the bundle  
jar only) that you can use to get everything, but then you have the  
downside of the startup/memory usage.    We probably need a page on  
the docs to document them all.   For example, the cxf-all contains:

     <import resource="classpath:META-INF/cxf/cxf.xml"/>
     <import resource="classpath:META-INF/cxf/cxf-extension-corba.xml"/>
     <import resource="classpath:META-INF/cxf/cxf-extension-jaxws.xml"/>
     <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
     <import resource="classpath:META-INF/cxf/cxf-extension-xml.xml"/>
     <import resource="classpath:META-INF/cxf/cxf-extension-addr.xml"/>
     <import resource="classpath:META-INF/cxf/cxf-extension-javascript- 
     <import resource="classpath:META-INF/cxf/cxf-extension-local.xml"/>
     <import resource="classpath:META-INF/cxf/cxf-extension- 
     <import resource="classpath:META-INF/cxf/cxf-extension-http- 
     <import resource="classpath:META-INF/cxf/cxf-extension-jms.xml"/>
     <import resource="classpath:META-INF/cxf/cxf-extension-object- 
     <import resource="classpath:META-INF/cxf/cxf-extension-http- 
     <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs- 
     <import resource="classpath:META-INF/cxf/cxf-extension- 
     <import resource="classpath:META-INF/cxf/cxf-extension-rm.xml"/>

And that doesn't include the cxf-extension-http or others that the  
above may be importing.  (http-jetty imports http).


> Cheers,
> Eoghan
> Daniel Kulp wrote:
>> Yea, really.  :-)
>> Seriously, if the there isn't a spring context listener, we'll  
>> create a default bus using our default bus configurations and grab  
>> the WEB-INF/cxf-servlet.xml file to load the cxf spring bean  
>> definitions. (jaxws:endpoint things for example).
>> This is "simple" to configure.   I think all of our samples if you  
>> do "ant war" in them, it generates a war that does it this way.     
>> I'd like to change the samples to using the spring context way of  
>> doing it, just never got around to it.
>> The downside is that application startup is slower and memory usage  
>> is higher.   The default bus created this way grabs ALL the cxf- 
>> extension-* stuff which is quite possibly more than you need.    
>> This takes a bit longer to initialize.   Also, since cxf- 
>> servlet.xml is processed in a child context, some things don't get  
>> injected quite the same as the definitions in the parent context  
>> aren't available in the subcontext.   It's something to be aware of.
>> Dan
>> On May 14, 2008, at 3:17 AM, John-M Baker wrote:
>>> Daniel.
>>> Really?  I thought a context loader was required to kick off  
>>> Spring, but
>>> I'm using other Spring related stuff too:  Here's an example:
>>> <context-param>
>>>   <param-name>contextConfigLocation</param-name>
>>>   <param-value>
>>>     classpath:configuration-context.xml
>>>     classpath:cxf-server-context.xml
>>>     classpath:datasource-ldap.xml
>>>   </param-value>
>>> </context-param>
>>> <!-- Loads the Spring application context -->
>>> <listener>
>>> <listener-class>org.springframework.web.context.ContextLoaderListener 
>>> </listener-class>
>>> </listener>
>>> <servlet>
>>>   <servlet-name>CXFServlet</servlet-name>
>>>   <display-name>CXF Servlet</display-name>
>>>   <servlet-class>
>>>     org.apache.cxf.transport.servlet.CXFServlet
>>>   </servlet-class>
>>>   <load-on-startup>1</load-on-startup>
>>> </servlet>
>>> <servlet-mapping>
>>>   <servlet-name>CXFServlet</servlet-name>
>>>   <url-pattern>/integration/*</url-pattern>
>>> </servlet-mapping>
>>> John Baker
>>> -- 
>>> Web SSO
>>> IT Infrastructure
>>> Deutsche Bank London
>>> URL:
>>> Daniel Kulp <>
>>> 13/05/2008 18:40
>>> Please respond to
>>> To
>>> cc
>>> Subject
>>> Re: do i need ContextLoaderListener?
>>> If you are using a cxf-servlet.xml type thing to define your  
>>> endpoint
>>> beans, then no, you don't need it.
>>> Dan
>>> On May 13, 2008, at 5:37 AM, Abid Hussain wrote:
>>>> Hi everybody,
>>>> I'm using tomcat 5.5.x. In my web.xml I put the following lines,
>>>> just because it was said so in the cxf-documentation:
>>>> <listener>
>>>>              <listener-class>
>>>> org.springframework.web.context.ContextLoaderListener
>>>>              </listener-class>
>>>> </listener>
>>>> As far as I understood, the ContextLoaderListener is used when the
>>>> context of the webapp is reloaded, which only happens if the  
>>>> content
>>>> of WEB-INF/classes (resp. WEB-INF/lib) changes.
>>>> The only way of deployment I use is by war-files. So am I right,
>>>> that the registration of the ContextLoaderListener in web.xml is  
>>>> not
>>>> needed in this case?
>>>> Regards,
>>>> Abid
>>>> -- 
>>>> Abid Hussain
>>>> Mail:
>>>> Web:
>>> ---
>>> Daniel Kulp
>>> ---
>>> This e-mail may contain confidential and/or privileged  
>>> information. If you are not the intended recipient (or have  
>>> received this e-mail in error) please notify the sender  
>>> immediately and delete this e-mail. Any unauthorized copying,  
>>> disclosure or distribution of the material in this e-mail is  
>>> strictly forbidden.
>>> Please refer to  
>>> for additional EU corporate and regulatory disclosures.
>> ---
>> Daniel Kulp
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4,  
> Ireland

Daniel Kulp

View raw message