2014-02-11 64 views
0

下文提到的是我的方面Spring AOP的错误0:未绑定

@Aspect 
public class TestAspect { 

    @Around("execution (* com.test..*(..))") 
    public void simonAspect(Joinpoint joinpoint) { 
     System.out.println(" --- Interceptor --- "); 

    } 

} 

和.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:mvc="http://www.springframework.org/schema/mvc" 
    ... /schema/aop/spring-aop-3.0.xsd"> 

    <mvc:annotation-driven /> 

    <aop:aspectj-autoproxy /> 

    <context:component-scan base-package="com.test" /> 

    <bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/view/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 

    <bean class="com.test.aspect.TestAspect" /> 


</beans> 

上部署我收到的异常产生的原因:java.lang.IllegalArgumentException异常:错误的:: 0正式在切入点无约束

我想拦截在com.test包中定义的控制器类的所有方法。

当我使用@component对类进行注释时,错误不会到来,但拦截器也不会被调用。

回答

0
@Around("execution (* com.test..*(..))") 

应该

@Around("execution (* com.test.*(..))") 

,或者您可以使用whitin这样

@Around("within (* com.test.*)") 
+0

关于更改这个我是geeting错误导致:java.lang.IllegalArgumentException:警告没有匹配这个类型名称:com.test [Xlint:invalidAbsoluteTypeName] – user2775185

0

一个Around方面希望你返回Object

所以,你一方面方法应该改变到

@Around("execution (* com.test..*(..))") 
public Object simonAspect(Joinpoint joinpoint) { 
    System.out.println(" --- Interceptor --- "); 

} 
0

问题是我使用Joinpoint而不是JoinPoint。应该来自org.aspectj.lang。*包的导入。