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

  • @Aspect & @Autowired

    Hi.

    I am using component-scanning and aspectj-autoproxy.

    Reading the spring docs, it seems as if I am able to inject other objects into my @Aspect since it's declared as any other bean in the spring xml.

    Is this the only way to do it? It would seem natural to have @Autowired working in @Aspect's if you are using component-scanning...?

    /Magnus

  • #2
    It is possible to use component scanning and annotation-based DI in your @Aspect classes. Just annotate your aspect with @Component in addition to @Aspect. For example:

    Code:
    @Aspect
    @Component
    public class MyAspect {
    
      @Autowired
      public MyAspect(DependentObject object) {
        ...
      }
    
      ...
    }
    You will still need the <aop:aspectj-autoproxy/> declaration in XML.

    Comment

    Working...
    X