Results 1 to 2 of 2

Thread: java.lang.ClassCastException: $Proxy121 cannot be cast to

  1. #1
    Join Date
    Sep 2012
    Posts
    1

    Default java.lang.ClassCastException: $Proxy121 cannot be cast to

    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.

    Code:
    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);
    	}
    }
    business-context.xml file entries
    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>
    Can some one please tell me what is going wrong out here? Any help is highly appreciated. Thanks in advance.
    Regards,
    Sumeet C

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Please use the search as this question has been answered numerous times before...

    In short use the interface (ScenarioDao) instead of the concrete class (ScenarioDaoImpl).. Read the reference guide especially the aop and proxy part....
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •