PDA

View Full Version : trial aop code not working


manojkar
Oct 10th, 2007, 07:19 AM
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.NameMatchMethodPoi ntcutAdvisor">
<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.FinderWelcome"/>

<bean id="log" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>com.hmco.college.finder.common.dao.springHistory.H istoryDAO</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.Transa ctionProxyFactoryBean">
<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.HibernateTransa ctionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>

<bean id="scopingTarget" scope="prototype" class="com.hmco.college.finder.common.dao.springHistory.H istoryDAOImpl">
<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

gregturn
Oct 10th, 2007, 09:15 AM
Can you re-edit your posting and wrap code with code tags?