Announcement Announcement Module
Collapse
No announcement yet.
Autowiring a Bean into an Aspect Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      Perfect, thanks!!

      Comment

      Working...
      X