I'm having problem with retrieving a bean from Spring using
ClassPathXmlApplicationContext.getBean(), given that the bean has Advisor
around it. I can't find exactly what I missed here. Any help is greatly
appreciated...

Here is my context xml:

<?xml version="1.0" encoding="UTF-8"?>
<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-2.0.xsd
            http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
            http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd";>

    <bean id="journalBuilder"
class="com.g1.emessaging.journal.e2.E2JournalBuilder"/>
    
    <bean id="transferArchiveAgent"
class="com.g1.emessaging.agent.TransferToArchiveAgent">
        <constructor-arg value="2000"/>
    </bean>

    <bean id="msgIndexDao"
        class="com.g1.emessaging.dao.hibernate.MsgIndexDaoHibernate">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

<!-- I'm just reusing here the transactionManager appfuse provides -->
    <aop:config>
        <aop:advisor id="archiveAgentTx" advice-ref="agentAdvice"
pointcut="execution(* *..agent.TransferToArchiveAgent.*(..))" order="3"/>
    </aop:config>
    
    <tx:advice id="agentAdvice">
        <tx:attributes>
            <tx:method name="doProcess*"/>
        </tx:attributes>
    </tx:advice>
    
</beans>

Here's my java class:

public class ArchiveRunner {
.... more code here...

  private static void doTransferToArchiveTest(String args[]) {
        logger.debug("--- Executing Transfer2Archive test ---");
        Integer loadFrequency = Integer.parseInt(args[0]);
        try {
            logger.debug("Starting thread . . .");
            TransferToArchiveAgent agentInstance = (TransferToArchiveAgent)
                   
SpringContextUtil.getBean(SpringContext.TRANSFER_ARCHIVE_AGENT);
            agentInstance.setInterval(loadFrequency);
            agentInstance.start();
            logger.debug("Please check log file ... log/emessaging.log");
        } catch (Exception e) {
            logger.debug("Archived UNSUCCESSFUL!");
            e.printStackTrace();
        }
        logger.debug("--- End of Transfer2Archive test ---");
    }
}

public class TransferToArchiveAgent {
... more code....

    /**
     * Default constructor
     *
     * @param interval
     *            process interval in milliseconds <code>long</code>
     */
    public TransferToArchiveAgent(long interval) {
        super("TransferToArchive", interval);
    }

    /*
     * (non-Javadoc)
     *
     * @see com.g1.emessaging.agent.Agent#doProcess()
     */
    @Override
    protected void doProcess() {
        JournalVo journal = null;
        List<MsgIndex> msgIndexRecords = getMessageIndexRecords();
        for (MsgIndex message : msgIndexRecords) {
//            journal = journalBuilder.convertToJournal(message);
            try {
                TransferToArchive.doTransfer(ProfileType.INPROFILE, message
                        .getInboundProfile(), journal, message.getId());
            } catch (ArchiveException ae) {
                ae.printStackTrace();
            } catch (JournalException je) {
                je.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

And here's some DEBUG logs of Spring:

[emessaging] DEBUG [main] DefaultListableBeanFactory.getSingleton(140) |
Creating shared instance of singleton bean 'transferArchiveAgent'
[emessaging] DEBUG [main] DefaultListableBeanFactory.createBean(348) |
Creating instance of bean 'transferArchiveAgent' with merged definition
[Root bean: class [com.g1.emessaging.agent.TransferToArchiveAgent];
scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true;
autowireMode=0; dependencyCheck=0; factoryBeanName=null;
factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined
in file
[D:\eDev\Projects\emessaging\core\target\classes\applicationContext-resources.xml]]
[emessaging] DEBUG [main]
DefaultListableBeanFactory.autowireConstructor(153) | Bean
'transferArchiveAgent' instantiated via constructor [public
com.g1.emessaging.agent.TransferToArchiveAgent(long)]
[emessaging] DEBUG [main] DefaultListableBeanFactory.createBean(399) |
Eagerly caching bean 'transferArchiveAgent' to allow for resolving potential
circular references
[emessaging] DEBUG [main] DefaultListableBeanFactory.getBean(206) |
Returning cached instance of singleton bean 'archiveAgentTx'
[emessaging] DEBUG [main] DefaultListableBeanFactory.getBean(206) |
Returning cached instance of singleton bean 'userManagerTx'
[emessaging] DEBUG [main] DefaultListableBeanFactory.getBean(206) |
Returning cached instance of singleton bean 'userManagerSecurity'
[emessaging] DEBUG [main] DefaultListableBeanFactory.getBean(206) |
Returning cached instance of singleton bean 'managerTx'
[emessaging] DEBUG [main] DefaultListableBeanFactory.getBean(206) |
Returning cached instance of singleton bean
'org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor'
[emessaging] DEBUG [main] DefaultListableBeanFactory.getBean(206) |
Returning cached instance of singleton bean 'agentAdvice'
[emessaging] DEBUG [main]
AnnotationAwareAspectJAutoProxyCreator.buildAdvisors(448) | Creating
implicit proxy for bean 'transferArchiveAgent' with 0 common interceptors
and 1 specific interceptors
[emessaging] DEBUG [main] JdkDynamicAopProxy.getProxy(111) | Creating JDK
dynamic proxy: target source is SingletonTargetSource for target object
[EMAIL PROTECTED]
[emessaging] DEBUG [main] ClassPathXmlApplicationContext.publishEvent(241) |
Publishing event in context
[EMAIL PROTECTED]:
[EMAIL PROTECTED]:
display name
[EMAIL PROTECTED];
startup date [Wed May 23 14:18:06 GMT+08:00 2007]; root of context
hierarchy]
[emessaging] DEBUG [main] DefaultListableBeanFactory.getBean(206) |
Returning cached instance of singleton bean 'transferArchiveAgent'
[emessaging] DEBUG [main] TransferToArchiveTest.doTransferToArchiveTest(44)
| Archived UNSUCCESSFUL!
java.lang.ClassCastException: $Proxy37
        at
com.g1.emessaging.archive.Transfer2ArchiveRunner.doTransferToArchiveTest(Transfer2ArchiveRunner.java:38)
        at
com.g1.emessaging.archive.Transfer2ArchiveRunner.main(Transfer2ArchiveRunner.java:29)[emessaging]
DEBUG [main] TransferToArchiveTest.doTransferToArchiveTest(47) | --- End of
Transfer2Archive test ---

Thanks in advance.
-- 
View this message in context: 
http://www.nabble.com/Injected-Bean-with-Advisor-throws-ClassCastException-tf3802232s2369.html#a10758206
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to