Results 1 to 3 of 3

Thread: Weave @Aspect to @controller

  1. #1

    Default 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. #2
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    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
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  3. #3

    Default

    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 !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •