Tuesday, February 25, 2014

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cxf' is defined

"org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cxf' is defined" This error wasted my precious couple of hours yesterday and could not find any blog post pointing to my problem. It seems this problem can occur for various reasons. 

few of them are not including cxf-bundle jar, not having proper cxf.xml files imported into spring context and this error can also occur for the wrong context file. What do I mean by it?

I had below code snippet in my web.xml.
-------------------------------
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>

My root-context.xml did not have any cxf related definition in it though I was loading the correct configuration file in CXFServlet servlet-mapping. I was hoping while loading the CXFServlet it will use the right configuration file and should work. 

But unfortunately after looking at CXFServlet source code realized that if the global config location is not null then only it consider local location. 

I just had to move my CXF related definition to root-context.xml and BOOM my problem was gone. I uploaded the working sample CXF project under my github repo. 


interesting isn't it
Manisha


No comments:

Post a Comment