2 drupal42 Drupal42 于 2014.09.25 10:01 提问

ProxyFactory 调用getProxy方法报ClassNotFoudException

初学Spring 自己写了一个测试用Demo,但是报错,求助。可能是低级错误,轻喷。

import java.lang.reflect.Method;

import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.framework.AopConfigException;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.interceptor.*;


public class TestPointCut {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        DataSet ds = new DataSet();
        MethodBeforeAdvice mba = new MethodBeforeAdvice() {

            @Override
            public void before(Method arg0, Object[] arg1, Object arg2)
                    throws Throwable {
                // TODO Auto-generated method stub

                System.out.println("Before...");
            }
        };

        ProxyFactory pf = new ProxyFactory();
        pf.setTarget(ds);
        try {
            pf.addAdvice(mba);
        } catch (AopConfigException e) {
            e.printStackTrace();
        }
        DataSet result = (DataSet) pf.getProxy();
        result.setName("Irwin");

    }

}

class DataSet{
    private String name;
    private String sex;
    private String age;
    public String getName() {
        System.out.println("getName");
        return name;
    }
    public void setName(String name) {
        System.out.println("setName");
        this.name = name;
    }
    public String getSex() {
        System.out.println("getSex");
        return sex;
    }
    public void setSex(String sex) {
        System.out.println("setSex");
        this.sex = sex;
    }
    public String getAge() {
        System.out.println("getAge");
        return age;
    }
    public void setAge(String age) {
        System.out.println("setAge");
        this.age = age;
    }


}

错误的提示是:
Caused by: java.lang.ClassNotFoundException: org.springframework.cglib.proxy.MethodInterceptor

求教我那里写错了?还是有缺失的jar包?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!