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

  • Autowired bean is null in Aspect

    Hi,

    I am trying to autowire a bean in my aspect class(Using Spring AOP 3.05) but at runtime the autowired bean is always null. The bean is declared with @Component. The code is something like this :

    MyAspect.java

    @Aspect
    @Component
    @Configurable(autowire = Autowire.BY_TYPE)
    public class MyAspect {

    protected final Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    LogManager logManager;

    @Pointcut(value = "execution(public * *(..)) ")
    public void anyPublicMethod() {
    }

    @Around("anyPublicMethod() && @annotation(logTry)")
    public Object logAction(ProceedingJoinPoint pjp, LogTry logTry)
    throws Throwable {
    Object retval = null;
    // Do what you want with the actionperformed
    String eventName = logTry.eventName();
    Class[] classes = logTry.clazz();
    String captionName = logTry.caption();

    logManager.log(eventName,captionName) // getting nullpointer here
    return retval;
    }
    }

    LogManager.java

    @Component
    public class LogManager {

    private final OpLogManager OpLogManager;

    @Autowired
    public LogManager (final OpLogManager OpLogManager){
    this.OpLogManager = OpLogManager;
    }
    //Some other Code.....

    }


    Kindly help.
    Regards
    Jubin
Working...
X