Results 1 to 2 of 2

Thread: trial aop code not working

  1. #1
    Join Date
    Oct 2007
    Posts
    2

    Default trial aop code not working

    Hi,
    I am trying to understand the aop concept by writing a simple application. The intent is that a simple message will be printed when the control enters a particular method. I am trying the MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice interfaces. I am pasting the appropriate code snippets

    <code>
    <bean id="logInterceptor" class="org.springframework.aop.support.NameMatchMe thodPointcutAdvisor">
    <property name="mappedName">
    <value>deleteScope</value>
    </property>
    <property name="advice">
    <ref bean="logAdvice"/>
    </property>
    </bean>

    <!--this is the advice -->
    <bean id="logAdvice" class="com.hmco.college.finder.webapp.admin.Finder Welcome"/>

    <bean id="log" class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="proxyInterfaces">
    <value>com.hmco.college.finder.common.dao.springHi story.HistoryDAO</value>
    </property>
    <property name="interceptorNames">
    <list>
    <value>logInterceptor</value>
    </list>
    </property>
    <property name="target">
    <ref bean="scopingMgr"></ref>
    </property>
    </bean>


    <bean id="scopingMgr" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager" ref="transactionManager"/>
    <property name="target" ref="scopingTarget"/>
    <property name="transactionAttributes">
    <props>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <!--<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>-->
    <!--<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>-->
    <!--<prop key="store*">PROPAGATION_REQUIRED</prop>-->
    </props>
    </property>
    </bean>


    <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    </bean>

    <bean id="scopingTarget" scope="prototype" class="com.hmco.college.finder.common.dao.springHi story.HistoryDAOImpl">
    <property name="sessionFactory" ref="sessionFactory"/>

    </bean>


    public class FinderWelcome implements MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice
    {

    public FinderWelcome()
    {
    System.out.println("come in the constructor of FinderWelcome");
    }

    public void before(Method method, Object[] objects, Object object) throws Throwable
    {
    // Scoping s = (Scoping)objects[0];
    System.out.println("Come aspect to delete id ");
    }

    public void afterReturning(Object arg0, Method arg1, Object[] arg2, Object arg3) throws Throwable
    {
    System.out.println("come in the after returning of finderwelcome");
    }

    public void afterThrowing(Method m, Object[] args, Object target, Throwable ex)
    {
    System.out.println("come in the afterThrowing of finderwelcome");
    }
    }


    method in HistoryDAOImpl

    public void deleteScope(Scoping scope) throws DataAccessException
    {
    getHibernateTemplate().delete(scope);
    getHibernateTemplate().flush();
    }

    </code>

    The problem is that none of the messages in the before or afterReturning are printed.

    -Manoj
    Last edited by manojkar; Oct 10th, 2007 at 08:23 AM. Reason: wrapped the code in <code/>

  2. #2
    Join Date
    Aug 2006
    Posts
    382

    Default Please re-edit your post with code tags

    Can you re-edit your posting and wrap code with code tags?
    Greg L. Turnquist (@gregturn), SpringSource/VMware
    Project Lead: Spring Python and author of Spring Python 1.1 and Python Testing Cookbook.
    Listen to Pond Jumpers, the international podcast for open source developers.
    These comments are my own personal opinions, and do not reflect those of my company.

Posting Permissions

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