I'm utilizing the Business Methods Interface pattern and Spring for implementing EJBs in my project. I built an example application that utilizes the pattern and have an interesting problem.
I'm running JBOSS 3.2.6 with Spring 1.1.1 and have my ear in the deploy directory and start JBOSS. The application executes correctly. Whenever I re-deploy (even without making code changes), I start getting a java.lang.ClassCastException in my onEjbCreate() method of my EJB. The offending line is:
Here's my EJB:Code:_businessMethods = (BusinessMethods) getBeanFactory().getBean("businessMethodsImpl");
My beanRefContext.xml is:Code:package com.mantechwva.examplej2ee.statelessejb; import javax.ejb.EJBException; import javax.ejb.CreateException; import javax.ejb.SessionContext; import org.springframework.ejb.support.*; import org.springframework.context.access.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * @ejb.bean name="BusinessMethods" * display-name="Name for Session Bean" * description="Description for Session Bean" * local-business-interface="BusinessMethods" * jndi-name="BusinessMethodsSLSB" * type="Stateless" * view-type="both" * @ejb.home extends="javax.ejb.EJBHome" * local-extends="javax.ejb.EJBLocalHome" * @ejb.interface extends="javax.ejb.EJBObject" * local-extends="javax.ejb.EJBLocalObject" * remote-class = "com.mantechwva.examplej2ee.statelessejb.BusinessMethodsRemote" */ public class BusinessMethodsBean extends AbstractStatelessSessionBean implements BusinessMethods { BusinessMethods _businessMethods; /** Logger for this class and subclasses */ protected final Log logger = LogFactory.getLog(getClass()); public BusinessMethodsBean() { super(); } /** * Business method * @ejb.interface-method view-type = "both" */ public String helloWorld() { return _businessMethods.helloWorld(); } /** * Business method * @ejb.interface-method view-type = "both" */ public String goodbyeWorld() { return _businessMethods.goodbyeWorld(); } /* (non-Javadoc) * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext) */ public void setSessionContext(SessionContext sessionContext) throws EJBException { super.setSessionContext(sessionContext); setBeanFactoryLocator(ContextSingletonBeanFactoryLocator.getInstance()); setBeanFactoryLocatorKey("ejbAC"); } /* (non-Javadoc) * @see javax.ejb.SessionBean#ejbRemove() */ public void ejbRemove() throws EJBException { // TODO : what if anything goes here? } /* * Must have the following method because XDoclet is stupid in some ways * and will create its own, causing the application context to not be loaded. */ public void ejbCreate() throws CreateException { super.ejbCreate(); } /* (non-Javadoc) * @see org.springframework.ejb.support.AbstractStatelessSessionBean#onEjbCreate() */ protected void onEjbCreate() throws CreateException { _businessMethods = (BusinessMethods) getBeanFactory().getBean("businessMethodsImpl"); } }
My ejbApplicationContext.xml is:Code:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <!-- - Application context definition for EJBs. --> <beans> <bean id="ejbAC" class="org.springframework.context.support.ClassPathXmlApplicationContext"> <constructor-arg> <list> <value>com/mantechwva/examplej2ee/statelessejb/config/ejbApplicationContext.xml</value> </list> </constructor-arg> </bean> </beans>
As far as I can see, it looks like I have everything set up correctly. And, the fact that it works correctly until I redeploy makes me think that it is some kind of bug in spring or have something to do with spring caching the class and it's surviving over redeploys.Code:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <!-- - Application context definition for EJBs. --> <beans> <!-- Link to EJB Implementation --> <bean id="businessMethodsImpl" class="com.mantechwva.examplej2ee.statelessejb.BusinessMethodsImpl"> </bean> </beans>
Has anyone seen this before or see that I have something incorrect?
thanks,
-Darell


Reply With Quote