Hello Techies,
I am getting the Class Cast Exception when I am trying to fetch a bean from the WebApplicationContext. Following is the code which is trying to access the bean.
business-context.xml file entriesCode:ServletContext servletContext = ServletMoeskContext.getServletContext(); WebApplicationContext webapp = WebApplicationContextUtils.getWebApplicationContext(servletContext); ScenarioDaoImpl jjj = (ScenarioDaoImpl) webapp.getBean("ScenarioDao",ScenarioDaoImpl.class); public class ServletMoeskContext { private static ServletContext ctx; public static void setServletContext(ServletContext servletContext) { ctx = servletContext; } public static ServletContext getServletContext() { return ctx; } } public class ServletContextProvider implements ServletContextAware{ public void setServletContext(ServletContext servletContext) { ServletMoeskContext.setServletContext(servletContext); } }
Can some one please tell me what is going wrong out here? Any help is highly appreciated. Thanks in advance.Code:<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitName" value="datapersistenceunit" /> <!-- <property name="dataSource" ref="dataSource" /> --> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <!-- <property name="showSql" value="${hibernate.showSql}" /> <property name="generateDdl" value="${hibernate.generateDdl}" /> <property name="databasePlatform" value="${hibernate.databaseDialect}" /> --> </bean> </property> <property name="jpaProperties"> <props> <prop key="hibernate.cache.use_second_level_cache">false</prop> <prop key="hibernate.cache.use_query_cache">false</prop> </props> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <tx:annotation-driven transaction-manager="transactionManager"/> <!-- Process the @PersistenceContext annotations in the daos --> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> <bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" /> <bean id="contextServletContextProvider" class="com.avaya.ept.moesk.server.context.ServletContextProvider" /> <bean id="ScenarioDao" class="com.avaya.aps.sca.ans.datalayer.imp.ScenarioDaoImpl" /> <bean id="placeholderConfigMM" class="com.avaya.ept.moesk.server.startup.PropertiesUtil"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/> <property name="locations"> <list> <value>classpath:settings.properties</value> </list> </property> </bean>
Regards,
Sumeet C


Reply With Quote