Exception in enabling Spring AOP (while creating RESTful service)

I am learning Spring & is in the process of creating a RESTful Service. I am trying to use AOP to find out the Execution time of all the public methods. But, getting exception during the creation of Servlet.

Given below is my code.

src/main/webapp/WEB-INF/springmvc-servlet.xml :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd"
>

    <context:component-scan base-package="com" />
    <context:annotation-config />
    <mvc:annotation-driven />
    <aop:aspectj-autoproxy/>
</beans>

com.aop.ExecutionTimeLoggingSpringAOP :

@Component
@Aspect
public class ExecutionTimeLoggingSpringAOP {

    final static Logger logger = Logger.getLogger(ExecutionTimeLoggingSpringAOP
.class);

    @Around("execution(public * *(..))")
    public Object profile(ProceedingJoinPoint pjp) throws Throwable {
        long startTime = System.nanoTime();
        String className = pjp.getTarget().getClass().getCanonicalName();
        String methodName = pjp.getSignature().getName();

        Object output = pjp.proceed();

        long elapsedTime = System.nanoTime() - startTime;

        logger.debug("Execution of " + className + "#" + methodName
                + " ended in " + new BigDecimal(elapsedTime).divide(
        new BigDecimal(1000000)) + " milliseconds");

        return output;
    }
}

Given below is the exception I am getting,

javax.servlet.ServletException: Servlet.init() for servlet springmvc threw exception
...
java.lang.Thread.run(Thread.java:745)
root cause

org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'org.springframework.web.servlet.mvc.method.
annotation.RequestMappingHandlerMapping#0': 
Initialization of bean failed; nested exception is org.springframework.beans.
ConversionNotSupportedException: ....

Am I missing something here?

PS : The REST API works when not using AOP(ie when aop:aspectj-autoproxy is removed from springmvc-servlet.xml)

Answers


Your pointcut expression is too generic. This will create proxies for all your Spring managed beans including the infrastructure beans. Try to be more specific (something like execution(* com.yourcompany.*.*(..))) to only proxy your component classes.


Need Your Help

What is the simplist way to detect a mobile device in a Grails application?

grails mobile

I have just started experimenting with Grails and would like to know the simplist method to detect a mobile browser.

Parser bracket regex

c# regex

I'm copletly noob of regex, but i'm forced to use it.