Java 启用SpringAOP时出现异常(创建RESTful服务时)

Java 启用SpringAOP时出现异常(创建RESTful服务时),java,spring,spring-mvc,spring-aop,Java,Spring,Spring Mvc,Spring Aop,我正在学习Spring&正在创建一个RESTful服务。我试图使用AOP来找出所有公共方法的执行时间。但是,在创建Servlet的过程中出现异常 下面是我的代码 src/main/webapp/WEB-INF/springmvcservlet.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http:

我正在学习Spring&正在创建一个RESTful服务。我试图使用AOP来找出所有公共方法的执行时间。但是,在创建Servlet的过程中出现异常

下面是我的代码

src/main/webapp/WEB-INF/springmvcservlet.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>
以下是我得到的一个例外

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: ....
我是不是遗漏了什么


PS:RESTAPI在不使用AOP时工作(即从
SpringMVCServlet.xml
中删除
AOP:aspectj autoproxy

您的切入点表达式太通用。这将为所有Spring管理的bean(包括基础结构bean)创建代理。尝试更具体一些(比如
execution(*com.yourcompany.................*(…)
),只代理您的组件类。

wow。这就成功了。一天来我一直在寻找解决办法。非常感谢你。以防有人需要知道答案。我有4个包
com.rj.domain
com.rj.repository
com.rj.controller
com.rj.aop
。我在(value=“execution(*com.rj.*(…))之前使用了以下表达式
@
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: ....