Announcement Announcement Module
Collapse
No announcement yet.
Weave @Aspect to @controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Weave @Aspect to @controller

    hi, is that possible to weave @aspect to @controller ?

    say i had

    Code:
    @Aspect
    public class mailAgent
    {
         .....
    
         @After( "execution(* com.web.RegisterController.register(..)" )
         public void sendmail() { /*send mail code */ }
    
         .....
    }
    Code:
    package com.web;
    
    @Controller
    public class RegisterController
    {
       private register(User user)  { /*do Something... */ }
    }
    however, I had try it and it can't work.

    any idea ?

    kiwi
    ----
    happy hacking !

  • #2
    This should work fine. However, you will need to declare a bean for the aspect and <aop:aspectj-autoproxy/> in you config file. See the 'petclinic' sample for an example.

    -Ramnivas

    Comment


    • #3
      hi, thx for reply.

      I had a @service on my @aspect (so spring will automatic initilize it) and put <aop:aspectj-autoproxy/>, but unfornutalety, it still couldn't work.

      here are some snippet of my log,

      [org.springframework.aop.aspectj.annotation.Reflect iveAspectJAdvisorFactory] - <Found AspectJ method: public void com.service.aspect.MailAgent.test()>

      (test() is my aspect method name)

      but when the code called, i didn't show anything (what i do is to System.out.println some words for testing purpose)

      if the aspect is fail to proxy, it will show "unable to apply advice to ..." right ?

      i had try on my my service's interface, it work ok, but it seem like fail on @controller concrete class, even i abstract my method to interface and pointcut to all methods in that interface, it still fail to run successfuly, even it show that

      [org.springframework.aop.aspectj.annotation.Reflect iveAspectJAdvisorFactory] - <Found AspectJ method: public void com.service.aspect.MailAgent.test()>

      any idea ?

      kiwi
      ----
      happy hacking !

      Comment

      Working...
      X