title: NullPointerException on @autowired dependency injection with Spring AOP
body: <p>I would like hijack the methods that are manipulated on database.
  For this i would like to use Spring AOP.
  But its getting NullPointerException when i didn't use @autowired depedency on my object.
  If i use this @autowired dependency AOP is not firing.</p>
  
  <p>Here is my my object initialization.</p>
  
  <pre><code>ApplicationContext context1 = new ClassPathXmlApplicationContext("Spring-Customer.xml");
  @Autowired
  EmployeeDAO dao = (EmployeeDAO) context1.getBean("employeeDAO");
  </code></pre>
  
  <p>This dao obect will be used in @Transactional method</p>
  
  <pre><code>@Transactional
      public void save(Employee employee) {
          dao.persist(employee);
      }
  </code></pre>
  
  <p>And i initialized the beam like this:</p>
  
  <pre><code>    &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
      http://www.springframework.org/schema/aop 
      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd "&gt;
  
      &lt;aop:aspectj-autoproxy proxy-target-class="true" /&gt;
  
      &lt;bean id="employeeDAO" class="com.timesheetz.employee.integration.EmployeeDAO " /&gt;
  
      &lt;!-- Aspect --&gt;
      &lt;bean id="logAspect" class="com.timesheetz.tools.service.LoggerAspect" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>The LoggerAspect Class that hijacks method is:</p>
  
  <pre><code> package com.timesheetz.tools.service;
  
  import java.util.Arrays;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.aspectj.lang.JoinPoint;
  import org.aspectj.lang.ProceedingJoinPoint;
  import org.aspectj.lang.annotation.AfterReturning;
  import org.aspectj.lang.annotation.AfterThrowing;
  import org.aspectj.lang.annotation.Around;
  import org.aspectj.lang.annotation.Aspect;
  import org.aspectj.lang.annotation.Before;
  import org.aspectj.lang.annotation.Pointcut;
  import org.springframework.core.annotation.Order;
  import org.springframework.stereotype.Component;
  
  @Aspect
  @Component
  public class LoggerAspect
  {
      private Log log = LogFactory.getLog(this.getClass());
  
      @Pointcut("execution(* *.*(..))")
      protected void loggingOperation() {}
  
      @Before("loggingOperation()")
      @Order(1)
      public void logJoinPoint(JoinPoint joinPoint)
      {
          System.out.println("Join point kind : " + joinPoint.getKind());
          System.out.println("Signature declaring type : "+ joinPoint.getSignature().getDeclaringTypeName());
          System.out.println("Signature name : " + joinPoint.getSignature().getName());
          System.out.println("Arguments : " + Arrays.toString(joinPoint.getArgs()));
          System.out.println("Target class : "+ joinPoint.getTarget().getClass().getName());
          System.out.println("This class : " + joinPoint.getThis().getClass().getName());
      }
  
      @AfterReturning(pointcut="loggingOperation()", returning = "result")
      @Order(2)
      public void logAfter(JoinPoint joinPoint, Object result)
      {
          System.out.println("Exiting from Method :"+joinPoint.getSignature().getName());
          System.out.println("Return value :"+result);
      }
  
      @AfterThrowing(pointcut="execution(* *.*(..))", throwing = "e")
      @Order(3)
      public void logAfterThrowing(JoinPoint joinPoint, Throwable e)
      {
          System.out.println("An exception has been thrown in "+ joinPoint.getSignature().getName() + "()");
          System.out.println("Cause :"+e.getCause());
      }
  
      @Around("execution(* *.*(..))")
      @Order(4)
      public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable
      {
          System.out.println("The method " + joinPoint.getSignature().getName()+ "() begins with " + Arrays.toString(joinPoint.getArgs()));
          try
          {
              Object result = joinPoint.proceed();
              System.out.println("The method " + joinPoint.getSignature().getName()+ "() ends with " + result);
              return result;
          } catch (IllegalArgumentException e)
          {
              System.out.println("Illegal argument "+ Arrays.toString(joinPoint.getArgs()) + " in "+ joinPoint.getSignature().getName() + "()");
              throw e;
          }        
      }
  
  }
  </code></pre>
  
  <p>And i inserted following tags in pom.xml</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
      &lt;version&gt;3.0.5&lt;/version&gt;
  &lt;/dependency&gt;
  
   &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
      &lt;version&gt;3.0.5&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;!-- Spring AOP + AspectJ --&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-aop&lt;/artifactId&gt;
      &lt;version&gt;3.0.5&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
      &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
      &lt;version&gt;1.6.11&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
      &lt;artifactId&gt;aspectjweaver&lt;/artifactId&gt;
      &lt;version&gt;1.6.11&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>I am using spring 3.0.5 version
  I have the jars
  aspectjrt.jar,version-1.6.11
  aspectjweaver.jar,version-1.6.11</p>