I created a sample Spring web application for implementing Spring AOP for logging purpose.I am not using annotations but xml configurations. I created a jsp and mapped it with a controller(HelloController). The controller in turn calls its BO AND Dao. I am using around advice in the class called LoggingAspect. If my controller uses handleRequest method then logAround method of Logging Aspect method is called and syso messages are executed. But if I remove handleRequest method and use formbackingobject method and onsubmit method in my controller, then my logAround method is not called at all. I don't get this. I need to implement the logging purpose for my controller which have formbackingObject method and onsubmit method and i dont want to use annotations. Kindly help
My Advice Class looks like:
public class LoggingAspect {
public void logAround(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("START:"+joinPoint.getTarget().getClass()+" METHOD:"+joinPoint.getSignature().getName());
Object value=joinPoint.proceed(); //continue on the intercepted method
System.out.println("END:"+joinPoint.getTarget().getClass()+" METHOD:"+joinPoint.getSignature().getName());
System.out.println("******");
}
}
My Controller looks like :
public class HelloController extends SimpleFormController {
protected final Log logger = LogFactory.getLog(getClass());
private BizLogic abc;
public BizLogic getAbc() {
return abc;
}
public void setAbc(BizLogic abc) {
this.abc = abc;
}
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("inside handle request");
String now = (new Date()).toString();
this.getAbc().getBoMesssage();
return new ModelAndView(new RedirectView("hello.htm"));
}
}
BO Class:
public class BizLogic {
private DataOperation data;
public DataOperation getData() {
return data;
}
public void setData(DataOperation data) {
this.data = data;
}
public void getBoMesssage()
{
System.out.println("BO");
this.getData().getDataDAO();
}
}
DAO Class:
public class DataOperation {
public void getDataDAO()
{
System.out.println("DAO");
}
}
Spring.xml file
<aop:aspectj-autoproxy />
<bean id="logAspect" class="com.adviceInSpring.LoggingAspect" />
<aop:config>
<aop:aspect id="aspectLoggging" ref="logAspect">
<aop:pointcut id="pointCutAround" expression="within(com.controller.*)||within(com.bo.*)||within(com.dao.*)"/>
<aop:around method="logAround" pointcut-ref="pointCutAround" />
</aop:aspect>
</aop:config>
<bean name="helloController" class="com.controller.HelloController">
<property name="abc" ref="boTest"/>
</bean>
<bean name="boTest" class="com.bo.BizLogic">
<property name="data" ref="daoTest"/>
</bean>
<bean name="daoTest" class="com.dao.DataOperation"></bean>
Output:
START:class com.controller.HelloController METHOD:handleRequest
inside handle request
START:class com.bo.BizLogic METHOD:getBoMesssage
BO
START:class com.dao.DataOperation METHOD:getDataDAO
DAO
END:class com.dao.DataOperation METHOD:getDataDAO
******
END:class com.bo.BizLogic METHOD:getBoMesssage
******
END:class com.controller.HelloController METHOD:handleRequest
******
Aucun commentaire:
Enregistrer un commentaire