Trouble Shooting(1)AOP Configuration

Trouble Shooting(1)AOP Configuration
Today, once I configured AOP around to my spring project. It gives me this kind of error message.

Error Message:
java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:254)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:835)

Solution:
Mostly, this is because of the parameters error. I put 3 parameters in my around method. But I only got 2 in the configuration file. That is the root cause. After I changed my configuration, my files are as follow:

<aop:aspect ref="advisor_catalogControllerImpl_search">
     <aop:pointcut id="catalogControllerImpl_search" expression="execution(* com.sillycat.graphite.web.controller.impl.CatalogControllerImpl.search(..)) and args(request,response,..)"/>
     <aop:before pointcut-ref="catalogControllerImpl_search" method="adviceBefore"/>
     <aop:around     pointcut-ref="catalogControllerImpl_search" method="adviceAround"/>
     <aop:after-returning pointcut-ref="catalogControllerImpl_search" returning="modelAndView" method="adviceAfterReturning"/>
</aop:aspect>

<bean id="advisor_catalogControllerImpl_search"                              class="com.sillycat.graphite.web.customization.CustomCabelasCatalogController_search"/>

public class CustomCabelasCatalogController_search extends
          ControllerAdvisorBase {
…snip…
}

public class ControllerAdvisorBase {

    public void runBefore(HttpServletRequest request, HttpServletResponse response) {
        // Need to be customized by store
    }

    public void runAfterReturning(HttpServletRequest request, HttpServletResponse response, ModelAndView modelAndView) {
        // Need to be customized by store
    }

    public Object runAround(ProceedingJoinPoint joinPoint, HttpServletRequest request, HttpServletResponse response) throws Throwable {
        // Need to be customized by store
        return joinPoint.proceed();
    }

    public final void adviceBefore(JoinPoint jp, HttpServletRequest request, HttpServletResponse response) {
        log("Entering", jp, null);
        runBefore(request, response);
    }

    public final void adviceAfterReturning(JoinPoint jp, HttpServletRequest request, HttpServletResponse response, ModelAndView modelAndView) {
        log("Exiting", jp, modelAndView);
        runAfterReturning(request, response, modelAndView);
    }

    public final Object adviceAround(ProceedingJoinPoint jp, HttpServletRequest request, HttpServletResponse response) throws Throwable {
        log("Around", jp, null);
        return runAround(jp, request, response);
    }

    private void log(String prefix, JoinPoint jp, ModelAndView modelAndView) {
        StringBuilder sb = new StringBuilder();
        sb.append(prefix).append(" ").append(jp.toString());

        if (logger.isDebugEnabled()) {
            Object[] args = jp.getArgs();
            if (args != null && args.length != 0) {
                sb.append(" with ").append(args.length).append(" args.\n");
                for (int i = 0; i < args.length; ++i)
                    sb.append("args[").append(i).append("]: ").append(args[i]).append("\n");
            }

            if (modelAndView != null)
                sb.append("Returned ").append(modelAndView);

            logger.debug(sb.toString());
        } else
            logger.info(sb.toString());
    }
   ...snip...
}


references:
http://forum.springsource.org/showthread.php?62460-Formal-unbound-in-pointcut


猜你喜欢

转载自sillycat.iteye.com/blog/1671561