Announcement Announcement Module
Collapse
No announcement yet.
java.lang.ClassCastException: $Proxy121 cannot be cast to Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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....

    Comment

    Working...
    X