title: Exception java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Aspect
body: <p>I recently started working on <code>AspectJ</code> and wrote a simple Aspect for Logging.</p>
  
  <p>I have defined below dependencies into my pom file:</p>
  
  <pre><code>        &lt;dependency&gt;
              &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
              &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
              &lt;version&gt;1.7.1&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.7.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-aspects&lt;/artifactId&gt;
          &lt;/dependency&gt;
  </code></pre>
  
  <p><strong>And Following artifacts are present in ear/lib folder:</strong></p>
  
  <ul>
  <li>aspectjrt-1.7.1.jar </li>
  <li>aspectjweaver-1.7.1.jar</li>
  <li>spring-aspects-3.2.1.RELEASE.jar</li>
  </ul>
  
  <p>I am getting below exception on service startup.:</p>
  
  <pre><code>05:59:18,325 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-15) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'calNamingBean' defined in ServletContext resource [/WEB-INF/helixservicebeans.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Aspect
                      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:452) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
                      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
                      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
                      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
                      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
                      at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:740) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE]
                      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:449) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE]
                      at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
                      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
                      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
                      at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.17.Final.jar:]
                      at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.17.Final.jar:]
                      at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:89) [jboss-as-web-7.1.3.Final.jar:7.1.3.Final]
                      at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
                      at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
                      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]
                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]
                      at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
              Caused by: java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Aspect
                      at org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactory.hasAspectAnnotation(AbstractAspectJAdvisorFactory.java:119) [spring-aop-3.1.1.RELEASE.jar:3.1.1.RELEASE]
                      at org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactory.isAspect(AbstractAspectJAdvisorFactory.java:115) [spring-aop-3.1.1.RELEASE.jar:3.1.1.RELEASE]
                      at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.isInfrastructureClass(AnnotationAwareAspectJAutoProxyCreator.java:100) [spring-aop-3.1.1.RELEASE.jar:3.1.1.RELEASE]
                      at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:278) [spring-aop-3.1.1.RELEASE.jar:3.1.1.RELEASE]
                      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:880) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
  </code></pre>
  
  <p><strong>Edit 1</strong> - I am using <code>JBOSS 7.1</code> and I think there are some issues with <code>AspejctJ</code> and <code>JBOSS</code>.</p>
  
  <p><a href="https://stackoverflow.com/questions/33164216/load-time-weaving-with-aspectj-in-jboss-as-7-1">https://stackoverflow.com/questions/33164216/load-time-weaving-with-aspectj-in-jboss-as-7-1</a></p>