Results 1 to 3 of 3

Thread: Autowiring a Bean into an Aspect

Hybrid View

  1. #1
    Join Date
    Dec 2009
    Posts
    5

    Default Autowiring a Bean into an Aspect

    I'd like to autowire a spring-managed bean into an Aspect. The following works like a champ:

    Code:
    @Aspect
    @Configurable
    public class PointWrapper {
       @Autowired
       private JobSupport job_support;
    
       (point-cuts-here)
    }
    I realized that I need to define a privileged aspect, which is not supported in @AspectJ. So I converted back to the retro AspectJ notation:

    Code:
    @Configurable
    public privileged aspect PointWrapper {
       @Autowired
       private JobSupport job_support;
    
       (point-cuts-here)
    }
    Problem is, this second syntax doesn't seem to work. I get a NullPointerException when referring to job_support. Is there a hack to make @Configurable / @Autowired work with old-school aspects?

    Thanks

    Norman

  2. #2
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    It seems that you don't need @Configurable in this case. Just instantiating the aspect as the following should do the trick (assuming that you have enabled autowiring):

    Note the factory-of attribute.

    Code:
    <bean class="mypackage.PointWrapper" factory-method="aspectOf"/>
    -Ramnivas
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  3. #3
    Join Date
    Dec 2009
    Posts
    5

    Default

    Perfect, thanks!!

Posting Permissions

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