0

I have a controller which doesn't implement any interface,am trying to write aspect for that controller,but it is throwing Exception"No adapter for handler : Does your handler implement a supported interface like Controller?"

public class OrderController extends BaseController{

@RequestMapping("/secure/admin/loadOrders.do")
public ModelAndView loadOrders(@ModelAttribute("orders") final Order order,BindingResult bindResult,final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse){
               // code


}

}

I have written logging aspect for controller

@Aspect
public class LoggingAspect {

@Before("execution(* com.cgt.web.admin.controller.OrderController.*(..))")
public void logBefore(JoinPoint joinPoint) {
    System.out.println("beforecalling method");
}

}

Web.xml

<context-param>
<param-name>contextConfigLocation</param-name>
    <param-value>
       /WEB-INF/beans/commons/application-context.xml
             </param-value>
         <servlet>  
            <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/beans/web/Controller-Beans.xml</param-value>
    </init-param>

    <load-on-startup>1</load-on-startup>
</servlet> 

in application-context.xml defined LoggingAspect bean

<mvc:annotation-driven />
<bean id="logAspect" class="com.cgt.aspect.LoggingAspect" />
   <aop:aspectj-autoproxy proxy-target-class="true"/>

Still getting "no handler adapter exception" as i mentioned above.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
seenu
  • 3
  • 2
  • Why do you have `` in your **application-context.xml** that should be in your `Controller-Beans.xml` also if you have configured everything correctly your controlelrs should be proxied because the aspect is in the root context and the controllers in your DispatcherServlets context. So in short your configuration seems flawed. – M. Deinum Nov 19 '13 at 11:33
  • @Seenu If you found my answer useful, would you mind giving it an upvote :) – Markus Coetzee Nov 25 '13 at 11:04

1 Answers1

0

Your configuration doesn't look quite right. As mentioned your <mvc:annotation-driven /> config needs to go into your MVC configuration and you should include your aspect:

<aop:aspectj-autoproxy>
    <aop:include name="logAspect"/>
</aop:aspectj-autoproxy>

Furthermore, here is a simple logging example using AOP and Spring which should show you the ropes. It also targets a MVC controller.

Community
  • 1
  • 1
Markus Coetzee
  • 3,384
  • 1
  • 29
  • 26