title: Spring Aop "Around.class" Class Not Found Exception
body: <pre><code>Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Around
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1095)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1040)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:505)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
      at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:220)
      at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:615)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:465)
      at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:139)
      at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:83)
      at com.springaoppractice.aop.AopMain.main(AopMain.java:12)
  
  Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Around
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1088)
      ... 13 more
  Caused by: java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Around
      at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.&lt;clinit&gt;(ReflectiveAspectJAdvisorFactory.java:74)
      at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.&lt;init&gt;(AnnotationAwareAspectJAutoProxyCreator.java:53)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
      ... 15 more
  </code></pre>
  
  <p>I can not figure out why am I getting this error my AspectJ Lib includes following jars:</p>
  
  <ul>
  <li>aspectjrt.jar</li>
  <li>aspectjweaver.jar</li>
  <li>cglib-2.2.2.jar</li>
  <li>aopalliance-1.0.jar</li>
  <li>asm-common-3.3.1.jar</li>
  </ul>
  
  <p><strong>Here is my main method:</strong></p>
  
  <pre><code>package com.springaoppractice.aop;
  
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  
  import com.springaoppractice.aop.service.ShapeService;
  
  public class AopMain {
  
      public static void main (String[] args){
  
          ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
          ShapeService shapeService = context.getBean("shapeService", ShapeService.class);
          System.out.println(shapeService.getCircle().getName());
  
      }
  }
  </code></pre>
  
  <p><strong>Here is my Aspect:</strong></p>
  
  <pre><code>package com.springaoppractice.aop.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("Logging advice initiazlied, get method is called!");
      }
  }
  </code></pre>
  
  <p><strong>Heres my ServiceClass:</strong></p>
  
  <pre><code>package com.springaoppractice.aop.service;
  
  import com.springaoppractice.aop.model.Circle;
  import com.springaoppractice.aop.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><strong>Here are my model:</strong></p>
  
  <pre><code>package com.springaoppractice.aop.model;
  
  public class Circle {
  
      private String name;
  
      public String getName(){
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  
  package com.springaoppractice.aop.model;
  
  public class Triangle {
  
      private String name;
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
  }
  </code></pre>
  
  <p><strong>Here is my SPRING.XML</strong></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-4.1.xsd
      http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;aop:aspectj-autoproxy/&gt;
  
      &lt;bean name="triangle" class="com.springaoppractice.aop.model.Triangle"&gt;
          &lt;property name="name" value="TRIANGLE NAME" /&gt;
      &lt;/bean&gt;
  
      &lt;bean name="circle" class="com.springaoppractice.aop.model.Circle"&gt;
          &lt;property name="name" value="CIRCLE NAME" /&gt;
      &lt;/bean&gt;
  
      &lt;bean name="shapeService" class="com.springaoppractice.aop.service.ShapeService" autowire="byName" /&gt;
      &lt;bean name="loggingAspect" class="com.springaoppractice.aop.aspect.LoggingAspect" /&gt;
  
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>Jars that are added to classpath:</strong>
  <img src="https://i.stack.imgur.com/NQTQM.png" alt="AspectJ Jars"></p>