title: No bean named 'cxf' is defined even after importing cxf.xml
body: <p>I tried to expose one of my method as REST webservice using Apache CXF. When I try to access the webservice at <strong><a href="http://localhost:7080/CXFwithMaven/services/book/abc" rel="nofollow">http://localhost:7080/CXFwithMaven/services/book/abc</a></strong> i get the following error. </p>
  
  <pre><code>javax.servlet.ServletException: Servlet.init() for servlet CXFServlet threw exception
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      java.lang.Thread.run(Thread.java:745)
  root cause
  
  org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cxf' is defined
      org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:694)
      org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1168)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:281)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
      org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:962)
      org.apache.cxf.transport.servlet.CXFServlet.loadBus(CXFServlet.java:75)
      org.apache.cxf.transport.servlet.CXFNonSpringServlet.init(CXFNonSpringServlet.java:76)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>I tried searching on the internet and found that this usually happens when you don't import cxf files such as </p>
  
  <pre><code>&lt;import resource="classpath:META-INF/cxf/cxf.xml" /&gt;
  &lt;import resource="classpath:META-INF/cxf/cxf-servlet.xml" /&gt;
  </code></pre>
  
  <p>Although i have imported the files, i am still getting the same error.</p>
  
  <p>Please see the below <strong>VO</strong>.
  package sample.cxfwithspring;</p>
  
  <pre><code>import javax.xml.bind.annotation.XmlRootElement;
  
  @XmlRootElement(name="Book")
  public class BookVO {
      private String name;
      private String author;
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getAuthor() {
          return author;
      }
  
      public void setAuthor(String author) {
          this.author = author;
      }
  
  }
  </code></pre>
  
  <p>And here is my <strong>service</strong>.</p>
  
  <pre><code>package sample.cxfwithspring;
  
  import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  import javax.ws.rs.PathParam;
  import javax.ws.rs.Produces;
  
  @Path("/book")
  public interface BookService {
  
      @GET
      @Produces("application/xml")
      @Path("/{name}")
      public BookVO getBook(@PathParam("{name}") String name);
  
  }
  </code></pre>
  
  <p>And <strong>serviceImpl</strong></p>
  
  <pre><code>package sample.cxfwithspring;
  
  public class BookServiceImpl implements BookService {
  
      public BookVO getBook(String name) {
          BookVO bookVO = new BookVO();
          bookVO.setAuthor("abc");
          bookVO.setName("Rest with CXF");
          return bookVO;
      }
  
  }
  </code></pre>
  
  <p><strong>Web.xml</strong></p>
  
  <pre><code>&lt;web-app id="WebApp_ID" version="2.4"
     xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
  
      &lt;display-name&gt;Archetype Created Web Application&lt;/display-name&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;classpath*:cxf.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;
              org.springframework.web.context.ContextLoaderListener
          &lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;CXFServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.apache.cxf.transport.servlet.CXFServlet&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;CXFServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/services/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>and <strong>cxf.xml</strong></p>
  
  <pre><code>&lt;beans xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:util="http://www.springframework.org/schema/util"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
      xsi:schemaLocation="
   http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/util
   http://www.springframework.org/schema/util/spring-util-2.0.xsd
   http://cxf.apache.org/jaxrs
   http://cxf.apache.org/schemas/jaxrs.xsd"&gt;
  
      &lt;import resource="classpath:META-INF/cxf/cxf.xml" /&gt;
      &lt;import resource="classpath:META-INF/cxf/cxf-servlet.xml" /&gt;
      &lt;jaxrs:server address="/" id="connectionService"&gt;
          &lt;jaxrs:serviceBeans&gt;
              &lt;ref bean="book" /&gt;
          &lt;/jaxrs:serviceBeans&gt;
          &lt;jaxrs:extensionMappings&gt;
              &lt;entry key="xml" value="application/xml"&gt;
              &lt;/entry&gt;
          &lt;/jaxrs:extensionMappings&gt;
  
      &lt;/jaxrs:server&gt;
      &lt;bean class="sample.cxfwithspring.BookServiceImpl" id="book"&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>pom.xml</strong></p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;Sample&lt;/groupId&gt;
      &lt;artifactId&gt;CXFwithMaven&lt;/artifactId&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;CXFwithMaven Maven Webapp&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;3.8.1&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
              &lt;version&gt;4.1.4.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
              &lt;version&gt;4.1.4.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
              &lt;version&gt;4.1.4.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
              &lt;version&gt;4.1.4.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
              &lt;artifactId&gt;cxf-rt-frontend-jaxrs&lt;/artifactId&gt;
              &lt;version&gt;2.7.8&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.codehaus.jettison&lt;/groupId&gt;
              &lt;artifactId&gt;jettison&lt;/artifactId&gt;
              &lt;version&gt;1.3.4&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.neethi&lt;/groupId&gt;
              &lt;artifactId&gt;neethi&lt;/artifactId&gt;
              &lt;version&gt;3.0.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.sun.xml.fastinfoset&lt;/groupId&gt;
              &lt;artifactId&gt;FastInfoset&lt;/artifactId&gt;
              &lt;version&gt;1.2.13&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.xml.bind&lt;/groupId&gt;
              &lt;artifactId&gt;jaxb-api&lt;/artifactId&gt;
              &lt;version&gt;2.1&lt;/version&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
      &lt;build&gt;
          &lt;finalName&gt;CXFwithMaven&lt;/finalName&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Please help me out as I am a newbie to Apche CXF and tried searching everywhere but wasn't able to find a solution for this.</p>