您现在的位置是:首页 > 电脑技术查询 > web开发

Spring2.5的@Aspect有关问题

编辑:chaxungu时间:2022-10-10 23:23:19分类:web开发

Spring2.5的@Aspect问题

各位,我在项目中是用了@Aspect的方式来处理切面。代码如下:

@Aspectpublic class LoginAspect {@Before("@annotation(userLogin)")public void rrr(UserLogin userLogin){System.out.println("我执行了"+this.getClass());}}

 要拦截的那个annotation代码如下:

@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.METHOD)public @interface UserLogin {}

 我在struts1.X 中的action中这样声明:

@UserLoginpublic ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {

 

在此action中注入了spring环境中的一个Service,并调用之:

 

@Resource(name="TbzyService")private TbzyService tbzyS;
//此处Service中的login方法也同样声明了@UserLogintbzyS.login(new XsaDlxx());

 当我钓用此action时,只能够在调用service时能对方法进行拦截,但钓用action的execute方法时并没有触发aop。action虽然没有接口,但是用cglib应该一样可以对其进行代理。而且也配置了aspectj-autoproxy 的proxy-target-class属性值为true。

百思不得其解,在Spring Community Forums找了一下午,最终未得其果。想请各位给看看。

配置文件如下,谢谢各位了!

<!--配置Spring--><aop:aspectj-autoproxy proxy-target-class="true"/><bean class="org.moyan.aspect.login.LoginAspect"></bean><!--声明action--><bean name="/zytb/xsdl" class="org.zzbm.struts.tbzy.action.XsdlAction" scope="request"></bean>

 

1 楼 moyan_java 2008-11-15 也许问题已经找到了。我在对Action进行调用的时候,使通过一个abstract的父类来调用子类自己实现的action方法的。这样也就算是类内部的调用了。也就无法使spring截获到此方法。