Organizational Research By

Surprising Reserch Topic

spring autowired bean for aspect aspect is null using -'java,spring,aop,aspectj,spring-aop'

spring autowired bean for aspect aspect is null  using -'java,spring,aop,aspectj,spring-aop'

I have the following spring configuration:

<context:component-scan base-package=""/>

<bean name="simpleEmailSender" class=""/>


Then I have an aspect:

public class SyncLoggingAspect {
    private SimpleEmailSender simpleEmailSender

    @AfterReturning(value="execution(*", returning="pusher")
    public void afterPoll(Pusher pusher) {      
        simpleEmailSender.send(new PusherEmail(pusher));

This aspect works (I can hit a breakpoint on afterPoll) but simpleEmailSender is null. Unfortunately I cannot find clear documentation on why this is.  (For the record, my simpleEmailSender bean exists and is correctly wired into other classes) The following things confuse me:

Is context:component-scan supposed to be picking up @Aspect?  If it is then surely it would be a spring managed bean, thus autowired should work?
If context:component-scan isn't for creating aspects, how is my aspect being created?  I thought aop:aspectj-autoproxy just creates a beanPostProcessor to proxy my @Aspect class?  How would it do this if it isn't a spring managed bean?

Obviously you can tell I don't have an understanding of how things should be working from the ground up.

asked Sep 7, 2015 by rajesh
0 votes

Related Hot Questions

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.