3 Replies Latest reply on Jul 23, 2008 8:26 PM by ragavgomatam

    CastClassException NamedXmlApplicationContext

    saish

      I have been trying to integrate JBoss, EJB3, JPA and Spring together. After a *lot* of experimentation, I finally stumbled on how to have the WAR Spring beans access the EAR Spring beans via JNDI.

      However, this solution has in some way interfered with regular SLSB deployment within JBoss. I am getting a CastClassException on org.jboss.naming.util.createSubcontext:69 org.jboss.spring.factory.NamedXmlApplicationContext.

      I am running JBoss 4.2.2-GA and Spring 2.5.4. I have tried both the 2.0 and 2.1 distros of the Spring Deployer. My application set-up (from the EAR down) is:

      META-INF
       application.xml
       jboss-app.xml
      foo.sping
       META-INF
       jboss-spring.xml
       [all other Spring JAR files]
      foo.jar
       META-INF
       ejb.jar.xml
       persistence.xml
      foo.war
       META-INF
       beanRefContext.xml (loads the EAR application context via JNDI)
       WEB-INF
       applicationContext.xml (blank)
       web.xml
      


      The SLSB is extremely simple. Basically it just has an isAlive() method returning boolean. Here is the stack.

      java.lang.ClassCastException: org.jboss.spring.factory.NamedXmlApplicationContext
       at org.jboss.util.naming.Util.createSubcontext(Util.java:69)
       at org.jboss.util.naming.Util.rebind(Util.java:125)
       at org.jboss.util.naming.Util.rebind(Util.java:113)
       at org.jboss.ejb3.stateless.BaseStatelessProxyFactory.bindProxy(BaseStatelessProxyFactory.java:231)
       at org.jboss.ejb3.stateless.BaseStatelessProxyFactory.start(BaseStatelessProxyFactory.java:216)
       at org.jboss.ejb3.stateless.StatelessLocalProxyFactory.start(StatelessLocalProxyFactory.java:101)
       at org.jboss.ejb3.ProxyDeployer.start(ProxyDeployer.java:105)
       at org.jboss.ejb3.SessionContainer.start(SessionContainer.java:157)
       at org.jboss.ejb3.stateless.StatelessContainer.start(StatelessContainer.java:102)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWrapper.java:103)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
       at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
       at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
       at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
       at $Proxy0.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:417)
       at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
       at $Proxy84.start(Unknown Source)
       at org.jboss.ejb3.JmxKernelAbstraction.install(JmxKernelAbstraction.java:120)
       at org.jboss.ejb3.Ejb3Deployment.registerEJBContainer(Ejb3Deployment.java:301)
       at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:362)
      


      This first SLSB is causing the issue. Existing JPA entity beans load fine.

      @Local
      @Stateless
      
      public class TestEjb implements Test {
      
       public boolean isAlive() {
       return true;
       }
      }
      


      I did read in another post that the issue was having Spring JAR files in the deployer that are incompatible with those in server/default/lib. I have the full-blown spring.jar in server/default/lib and have removed all JAR's from the deployer except spring-deployer.jar.

      My guess is that JBoss is looking in the nested JNDI context that beanRefContext.xml created and finding an instance of ApplicationContext rather than Context. But I have no idea how to fix it.

      Thanks!

      - Saish