日期:2014-05-18  浏览次数:20774 次

第一个spring AOP出现问题,麻烦各位看一下,谢谢
错误提示
BatchFile code
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userManager' defined in class path resource [applicationContext-bean.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut allAddMethod


Java code
package com.bjsxt.spring;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

/**
 * 定义Aspect
 * @author Administrator
 *
 */
@Aspect
public class SecurityHandler {
    
    /**
     * 定义Pointcut,Pointcut的名称就是allAddMethod,此方法不能有返回值和参数,该方法只是一个
     * 标识
     * 
     * Pointcut的内容是一个表达式,描述那些对象的那些方法(订阅Joinpoint)
     */
    @Pointcut("execution(* add*(..)) || execution(* del*(..))")
    private void allAddMethod(){};
    
    /**
     * 定义Advice,标识在那个切入点何处织入此方法
     */
    @Before("allAddMethod()")
    private void checkSecurity() {
        System.out.println("----------checkSecurity()---------------");
    }
    
}



配置文件
XML code
<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
    <aop:aspectj-autoproxy></aop:aspectj-autoproxy>
    <bean id="securityHandler" class="com.bjsxt.spring.SecurityHandler"></bean>
    <bean id="userManager" class="com.bjsxt.spring.UserManagerImpl"></bean>
</beans>


麻烦各位兄台帮看一下,谢谢了

------解决方案--------------------
哦,小case,你的代码应该没有什么问题,应该是aspectj与JDK1.6的兼容性不好,解决方法换成jdk1.5
或者升级aspectj,最新的是aspectj1.6.2 下载地址如下:
http://www.eclipse.org/downloads/download.php?file=/tools/aspectj/aspectj-1.6.2.jar