Results 1 to 2 of 2

Thread: Class cast exception in bean injection

  1. #1
    Join Date
    Jul 2012
    Posts
    1

    Default Class cast exception in bean injection

    Hi,

    I have configured the bean in xml as given below.

    <bean id="searchDAO" parent="txProxyTemplate"> ...


    <bean id="txProxyTemplate" abstract="true"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref bean="transactionManager" />
    </property>
    <property name="preInterceptors">
    <list>
    <ref bean="exceptionInterceptor" />
    <!-- <ref local="methodTimeInterceptor" /> -->
    </list>
    </property>

    <property name="transactionAttributes">
    <props>
    <prop key="save*">
    PROPAGATION_REQUIRED,-com.radaptive.common.exception.RttException
    </prop>
    <prop key="update*">
    PROPAGATION_REQUIRED,-com.radaptive.common.exception.RttException
    </prop>
    <prop key="delete*">
    PROPAGATION_REQUIRED,-com.radaptive.common.exception.RttException
    </prop>
    <prop key="*">
    PROPAGATION_REQUIRED,-com.radaptive.common.exception.RttException
    </prop>
    </props>
    </property>
    </bean>

    Am getting the bean like

    WebApplicationContext context;
    SearchDAOImpl searchDAO = (SearchDAOImpl)context.getBean("searchDAO");


    While accessing bean like this I am getting the class cast exception like

    $Proxy17 cannot be cast to com.radaptive.rdpv.search.dao.impl.SearchDAOImpl


    Thanks in advance

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

    Default

    Please use [ code][/code ] tags when posting code that way it remains readable ...

    Plese use the forum post as this question has been answered numerous times before I also suggest a read of the aop chapter of the reference guide.

    Short answer: Program to interfaces not concrete classes. Next to that don't use the TransactionProxyFactoryBean as it should be considered deprecated since the introduction of the new aop configuration (Spring 2.0).
    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
  •