title: Getting "java.lang.ClassCastException: class org.apache.cxf.bus.spring.SpringBusFactory" in TomEE
body: <p>I'm currently using CXF 3.1.9 and Spring 4.3.5 in an app built with Gradle, and running in Tomcat 8 (TomEE 7.0.1).</p>
  
  <p>I currently only specify the following explicit CXF dependencies:</p>
  
  <pre><code>['cxf-rt-rs-extension-providers', 'cxf-rt-management'].each { 
      compile "org.apache.cxf:${it}:3.1.9"
  }
  </code></pre>
  
  <p>This gets several other artifacts transitively, including cxf-core.</p>
  
  <p>Up to now, the app has just been serving REST requests, and it's been working fine.  I'm now trying to add a simple request out to another service, using ClientBuilder.  When I try to send that message, I get this:</p>
  
  <pre><code>SEVERE: Failed to determine BusFactory implementation class name.
  java.lang.ClassCastException: class  org.apache.cxf.bus.spring.SpringBusFactory
      at java.lang.Class.asSubclass(Class.java:3404)
      at org.apache.cxf.BusFactory.getBusFactoryClass(BusFactory.java:390)
  </code></pre>
  
  <p>I noticed that some other people have gotten a similar error, but I don't see a solution that makes sense for my situation.</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>I figured there's a classloading conflict here, so I turned on verbose classloading, and I do see CXF classes being loaded both from my webapp WEB-INF/lib, and from the container's "lib" directory, specifically the "BusFactory" class.</p>
  
  <p>However, I believe I have all the proper settings to convince TomEE to load all CXF classes from the webapp, instead of the container.  I have "openejb.classloader.forced-load=org.springframework,org.apache.cxf" in the "system.properties" file in the Server definition in Eclipse, and I have "disabled=true" in "cxf.properties" and "cxf-rs.properties" in the same place.</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>I also noticed that upon my first reference to "ClientBuilder", it's loading that class from the container's lib, so I tried adding "javax.ws.rs.client" to the "forced-load" list.  Unfortunately, that just resulted in a different exception:</p>
  
  <pre><code>org.apache.cxf.interceptor.Fault: ClassCastException: attempting to castjar:file:.../apache-tomee-webprofile-7.0.1/lib/javaee-api-7.0.jar!/javax/ws/rs/client/ClientBuilder.class to jar:file:.../.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/uslMonitorService/WEB-INF/lib/javax.ws.rs-api-2.0.1.jar!/javax/ws/rs/client/ClientBuilder.class
      at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:162)
      at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:128)
      at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:189)
      at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:99)
      ...
  Caused by: java.lang.LinkageError: ClassCastException: attempting to castjar:file:.../apache-tomee-webprofile-7.0.1/lib/javaee-api-7.0.jar!/javax/ws/rs/client/ClientBuilder.class to jar:file:.../.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/uslMonitorService/WEB-INF/lib/javax.ws.rs-api-2.0.1.jar!/javax/ws/rs/client/ClientBuilder.class
      at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:97)
      at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:114)
  </code></pre>