继承MethodBeforeAdvice

CTBOK 2009-12-21 05:22:11
我正在看书,里面的代码如下:

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)
请问为什么?谢谢
...全文
194 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
道光2008 2009-12-21
  • 打赏
  • 举报
回复
改为:
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] = "超人";
}
}
}
CTBOK 2009-12-21
  • 打赏
  • 举报
回复
找出问题了,import那里应该是:
import org.springframework.aop.*;
import java.lang.reflect.*;
道光2008 2009-12-21
  • 打赏
  • 举报
回复
The type BeforeAdvice1 must implement the inherited abstract method

BeforeAdvice1 必须实现MethodBeforeAdvice 虚方法
CTBOK 2009-12-21
  • 打赏
  • 举报
回复
补充一下,是spring 2.5.6
AspireHouse 2009-12-21
  • 打赏
  • 举报
回复
在错误处ctrl+1 看看它自动帮你重写的方法与你的哪不一样了,你的方法肯定哪写错了
阿_布 2009-12-21
  • 打赏
  • 举报
回复
检查一下Method类有没有导错包。

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧