Announcement Announcement Module
Collapse
No announcement yet.
org.springframework.beans.factory.BeanNotOfRequire dTypeException: Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • org.springframework.beans.factory.BeanNotOfRequire dTypeException:

    Hi,
    I am getting the following exception while trying to call @Transactional annotation in my class.
    I know this has been answered a thousand times but I don't see a solution in the older threads
    I am new to spring ...so pls help me out

    PHP Code:
    Bean named 'reporterService' must be of type [com.gsm.reporter.service.ReporterServiceImpl], but was actually of type [$Proxy59]
    org.springframework.beans.factory.BeanNotOfRequiredTypeExceptionBean named 'reporterService' must be of type [com.gsm.reporter.service.ReporterServiceImpl], but was actually of type [$Proxy59]
        
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:349)
        
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
        
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1079)
        
    at com.gsm.reporter.HourlyReporter.execute(HourlyReporter.java:38)
        
    at org.quartz.core.JobRunShell.run(JobRunShell.java:216
    The following is my code from where context is initialized and the service is called :

    ApplicationContext appContext = new ClassPathXmlApplicationContext(new String[]{"com/gsm/reporter/context.xml"});

    ReporterService reporterService = appContext.getBean("reporterService",ReporterServi ceImpl.class);
    reporterService.fireEngine();

    The following is my SERVICE CODE :

    HTML Code:
    @Transactional(readOnly = true)
    public class ReporterServiceImpl extends BaseDaoSupport implements ReporterService {
        static NonCatalogLogger log = new NonCatalogLogger("ReporterServiceImpl");
    
        @Override
        @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
        public void fireEngine() {
            log.info("entering the trasaction method");
            Session session = null;
            try {
                session = getHibernateSession();
                List<TrkIO> listTrkIos = getHibernateTemplate().find("from R_TRKIO where DIRTY=1");
                for (TrkIO trkIO : listTrkIos) {
                  //setImpClicksForAgrIO(session,trkIO);
                     log.info("transaction going on--->");
                }
            } catch (Throwable th) {
               log.error("Exception in ReporterService",th);
            } finally {
                closeHibernateSession(session);
            }
            //To change body of implemented methods use File | Settings | File Templates.
        }
    }
    ReporterService is just an interface.....since I want to use JDK DYNAMIC PROXY
    The following is my context.xml(spring config file)

    PHP Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
           
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           
    xmlns:aop="http://www.springframework.org/schema/aop"
           
    xmlns:tx="http://www.springframework.org/schema/tx"
           
    xsi:schemaLocation="
         http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
         http://www.springframework.org/schema/tx
         http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
         http://www.springframework.org/schema/aop
         http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
    >

        <
    bean id="jndiObject" abstract="true" class="org.springframework.jndi.JndiObjectFactoryBean">
        </
    bean>

        <
    bean id="reporterDS" parent="jndiObject">
            <
    property name="jndiName" value="mi_admin"/>
        </
    bean>

        <!-- 
    the following is hibernate configuration via spring -->

        <
    bean id="sessionFactory"
              
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <
    property name="dataSource" ref="reporterDS"/>
            <
    property name="mappingResources">
                <list>
                    <
    value>com/gsm/reporter/model/TrkIO.hbm.xml</value>
                    <
    value>com/gsm/reporter/model/AgrIO.hbm.xml</value>
                    <
    value>com/gsm/reporter/model/BrkIODev.hbm.xml</value>
                    <
    value>com/gsm/reporter/model/BrkIOClicks.hbm.xml</value>
                    <
    value>com/gsm/reporter/model/BrkIOViews.hbm.xml</value>
                </list>
            </
    property>
            <
    property name="hibernateProperties">
                <
    props>
                    <
    prop key="hibernate.show_sql">false</prop>
                    <
    prop key="hibernate.dialect">org.hibernate.dialect.Oracle9iDialect</prop>
                    <
    prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>
                    <
    prop key="hibernate.transaction.manager_lookup_class">
                        
    org.hibernate.transaction.WeblogicTransactionManagerLookup
                    
    </prop>
                </
    props>
            </
    property>
        </
    bean>

        <
    bean id="reporterService" class="com.gsm.reporter.service.ReporterServiceImpl">
            <
    property name="sessionFactory" ref="sessionFactory"/>
        </
    bean>


        <
    tx:annotation-driven transaction-manager="txManager"   />
        <
    bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <
    property name="sessionFactory" ref="sessionFactory"/>
        </
    bean>

    </
    beans
    Please help me

  • #2
    Please use the search as that question (proxying) has been answered numerous time before. I suggest a read of the aop chapter especially the part explaining proxies.

    Spring uses proxies (in your case JDK Dynamic Proxies) which basically mean you get a dynamic class ($ProxySomething) which acts like the interfaces it implements. You should change your getBean to check for the interface not the concrete implementation.

    Comment


    • #3
      Hi Marten,
      Thanks a LOT for the solution.Actually I thought the same but some how missed it.
      I have one more question :
      What if my transactional method has another methods which again are transactional.
      I cannot call it from outside the class.I know I have to use AspectJ for that.
      But can you throw some light with the help of some example code ?

      Comment

      Working...
      X