我正在看书,里面的代码如下:package com.java.chapter23;import org.aspectj.apache.bcel.classfile.Method;
import org.springframework.aop.MethodBeforeAdvice;public class BeforeAdvice1 implements MethodBeforeAdvice {     <--出错行
public void before(Method method, Object[] args , Object target) throws Throwable {
System.out.println("before Advice:" + target.getClass().getName() + "." + method.getName() + " 参数值:" + args[0]);
if (method.getName().equals("getHello")) {
args[0] = "超人";
}
}
}提示BeforeAdvice1那里出错,提示如下:
The type BeforeAdvice1 must implement the inherited abstract method 
 MethodBeforeAdvice.before(Method, Object[], Object)
请问为什么?谢谢

解决方案 »

  1.   

    检查一下Method类有没有导错包。 
      

  2.   

    在错误处ctrl+1  看看它自动帮你重写的方法与你的哪不一样了,你的方法肯定哪写错了
      

  3.   

    The type BeforeAdvice1 must implement the inherited abstract method BeforeAdvice1 必须实现MethodBeforeAdvice 虚方法
      

  4.   

    找出问题了,import那里应该是:
    import org.springframework.aop.*;
    import java.lang.reflect.*;
      

  5.   

    改为:
    import java.lang.reflect.Method;import org.springframework.aop.MethodBeforeAdvice;public class BeforeAdvice1 implements MethodBeforeAdvice {
    @Override
    public void before(Method method, Object[] args, Object target)
    throws Throwable {
    // TODO Auto-generated method stub
    System.out.println("before Advice:" + target.getClass().getName() + "."
    + method.getName() + " 参数值:" + args[0]);
    if (method.getName().equals("getHello")) {
    args[0] = "超人";
    }
    }
    }