实现aop..java.lang.IllegalArgumentException:错误在:: 0正式未绑定的切入点

时间:2015-04-13 19:44:11

标签: java spring annotations aspectj spring-aop

我是Spring AOP的新手。试图在我的项目中实现AOP。当我运行以下代码时,我收到此错误。回应真的很感激。

Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut
    at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:301)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:203)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:189)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:167)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:208)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:262)
    at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:294)
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Authenticator {
    boolean byPassAuthentication() default false;
}
@Aspect
public class PointcutDefinition {   
    @Pointcut("within(com.test.services..*)")
    public void authenticator() {}
}
@Aspect
public class AccountLoggingAspect {
    @Before(value = "com.test.aop.PointcutDefinition.authenticator() && @annotation(auth)")
    public void authenticatorlogging(Authenticator auth) {
        System.out("test");
    }
}
@Transactional(propagation=Propagation.REQUIRES_NEW)
@Aspect
public class AspectAuditor {
    @Pointcut("within(com.test..*)")
    public void auditPtCut() {}

    @Before(value = "auditPtCut() && @annotation(log)")
    public void beforeMethod(JoinPoint jp, AuditLog log) {
        if (log.enable())
            Audit.startTask(jp.getSignature().getName());
    }
}
<aop:aspectj-autoproxy />
<bean id="loggingAspect" 
    class="com.test.aop.AccountLoggingAspect">
</bean>
    <bean id="loggingAspectAuditor" 
    class="com.test.aop.AspectAuditor">
</bean>

现在将此代码添加到xml ..现在得到不同的错误

<aop:aspectj-autoproxy />

<bean id="loggingAspect" 
    class="com.test.aop.AccountLoggingAspect">
</bean>
    <bean id="loggingAspectAuditor" 
    class="com.test.aop.AspectAuditor">
</bean>

<aop:config>
    <aop:advisor pointcut="com.test.aop.PointcutDefinition()" advice-ref="tx-advice"/>
</aop:config>

<tx:advice id="tx-advice" transaction-manager="transactionManager">
  <tx:attributes>
    <tx:method name="*" propagation="REQUIRED"/>
  </tx:attributes>
</tx:advice>
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.annotation.AnnotationCacheOperationSource#0': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error can't bind type name 'com.test.aop'
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)

1 个答案:

答案 0 :(得分:0)

也许你想改变这个

<aop:advisor pointcut="com.test.aop.PointcutDefinition()" advice-ref="tx-advice"/>

到那个

<aop:advisor pointcut="com.test.aop.PointcutDefinition.authenticator()" advice-ref="tx-advice"/>

这应该可以解决语法错误。

至于在Spring AOP中制作方面或建议事务,我不知道是否可能,因为我不是Spring用户,另请参阅my answer here