title: AOP using AspectJ not working with <aop:aspectj-autoproxy />
body: <p>I am new to spring framework and was trying some sample examples to understand the AOP and here is what I did till now, but its not working.</p>
  
  <p>The problem is as soon as I add <code>&lt;aop:aspectj-autoproxy /&gt;</code> to spring.xml my build fails saying not able to create bean with null pointer exception.
  But If I run the app without <code>&lt;aop:aspectj-autoproxy /&gt;</code> tag then it runs fine <strong>but without AOP.</strong></p>
  
  <p>Here are few details of my project.
  <img src="https://i.stack.imgur.com/QXtFg.png" alt="enter image description here"></p>
  
  <p>Here I have AopMain which is the main class which runs,
       LoggingAspect Where I actually defined the <strong>before aspect</strong> 
       Have two models Circle and Triangle
       ShapeService which actually uses the above two models</p>
  
  <p>And Here am giving the code for them</p>
  
  <p>AopMain: </p>
  
  <pre><code>package com.spring.aop;
  
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  
  import com.spring.service.ShapeService;
  
  public class AopMain {
  
  /**
   * @param args
   */
  public static void main(String[] args) {
  
      ApplicationContext ctx = new ClassPathXmlApplicationContext("Spring.xml");
      ShapeService shapeService =  ctx.getBean("shapeService", ShapeService.class); 
      System.out.println(shapeService.getCircle().getName());
  }
  
  }
  </code></pre>
  
  <p>LoggingAspect: </p>
  
  <pre><code>package com.spring.aspect;
   import org.aspectj.lang.annotation.Aspect;
   import org.aspectj.lang.annotation.Before;
  
  @Aspect
  public class LoggingAspect {
  
  @Before("execution(public String getName())")
  public void loggingAdvice(){
      System.out.println("Advice run, Get method called");
  }
  }
  </code></pre>
  
  <p>Circle:</p>
  
  <pre><code>package com.spring.model;
  
  public class Circle {
  
  private String name;
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Triangle: Same as circle with single attribute name</p>
  
  <p>ShapeService:</p>
  
  <pre><code>package com.spring.service;
  
  import com.spring.model.Circle;
  import com.spring.model.Triangle;
  
  public class ShapeService {
  
  private Circle circle;
  private Triangle triangle;
  
  public Circle getCircle() {
      return circle;
  }
  public void setCircle(Circle circle) {
      this.circle = circle;
  }
  public Triangle getTriangle() {
      return triangle;
  }
  public void setTriangle(Triangle triangle) {
      this.triangle = triangle;
  }
  
  
  }
  </code></pre>
  
  <p>And Now here comes the important file Spring.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &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-2.0.xsd
              http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
              http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"&gt;
  
  &lt;aop:aspectj-autoproxy /&gt;
  
  &lt;bean name="triangle" class="com.spring.model.Triangle"&gt;
  &lt;property name="name" value="Triagnle Name"/&gt;
  &lt;/bean&gt;
  
  &lt;bean name="circle" class="com.spring.model.Circle"&gt;
  &lt;property name="name" value="Circle Name"/&gt;
  &lt;/bean&gt;
  
  &lt;bean name="shapeService" class="com.spring.service.ShapeService" autowire="byName" /&gt;
  
  &lt;bean name="loggingAspect" class="com.spring.aspect.LoggingAspect"/&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Am getting the error as follows:</p>
  
  <pre><code>Error creating bean with name 'triangle' defined in class path resource [Spring.xml]: Initialization of bean failed; nested exception is java.lang.NullPointerException
  </code></pre>
  
  <p>But if I try to comment the <code>&lt;aop:aspectj-autoproxy /&gt;</code> line in Spring.xml and run the code it is able to create the bean.
   Please guide me am I missing some thing? Some library or is it some library conflict?</p>
  
  <p>Something to do with <code>&lt;aop:aspectj-autoproxy /&gt;</code></p>