2012-11-18 15 views
9

'daki JavaBrains eğiticisini takip ederken şu istisnaı alıyorum: Javabrains'deki yay yönü programlama eğitimlerini takip ediyorum. http://javabrains.koushik.org/2011/08/spring-tutorial-27-writing-our-first.html Ben gerekli kütüphaneleri projeye alınmadan ve ben IDE hiçbir uyarı olsun, ama kodu çalıştırdığınızda ben şu İstisna olsun: Özellikle bu eğitimde olduğumSpring Aspect Programming:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'triangle' defined in class path resource [spring.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/tools/PointcutDesignatorHandler 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:452) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) 
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) 
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) 
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) 
at org.koushik.javabrains.AopMain.main(AopMain.java:18) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:601) 
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) 
Caused by: java.lang.NoClassDefFoundError: org/aspectj/weaver/tools/PointcutDesignatorHandler 
at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.getPointcut(ReflectiveAspectJAdvisorFactory.java:145) 
at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.getAdvisor(ReflectiveAspectJAdvisorFactory.java:130) 
at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory$1.doWith(ReflectiveAspectJAdvisorFactory.java:74) 
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:473) 
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:451) 
at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.getAdvisors(ReflectiveAspectJAdvisorFactory.java:70) 
at org.springframework.aop.aspectj.annotation.BeanFactoryAspectJAdvisorsBuilder.buildAspectJAdvisors(BeanFactoryAspectJAdvisorsBuilder.java:109) 
at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.findCandidateAdvisors(AnnotationAwareAspectJAutoProxyCreator.java:86) 
at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:107) 
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:278) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:880) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:852) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:446) 
... 15 more 
Caused by: java.lang.ClassNotFoundException: org.aspectj.weaver.tools.PointcutDesignatorHandler 
at java.net.URLClassLoader$1.run(URLClassLoader.java:366) 
at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:423) 
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:356) 
... 28 more 
Process finished with exit code 1 

Benim sınıf dosyaları ve spring.xml:

Ana sınıfı:

package org.koushik.javabrains; 

import org.koushik.javabrains.service.ShapeService; 
import org.springframework.context.ApplicationContext; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 


public class AopMain { 

    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()); 
    } 
} 

ShapeService sınıfı:

package org.koushik.javabrains.service; 

import org.koushik.javabrains.model.Circle; 
import org.koushik.javabrains.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; 
    } 
} 

Çember sınıfı:

package org.koushik.javabrains.model; 

public class Circle { 

    private String name; 

    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 
} 

Üçgen sınıfı:

package org.koushik.javabrains.model; 

public class Triangle { 

    private String name; 

    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 
} 

LoggingAspect sınıfı:

package org.koushik.javabrains.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"); 
    } 
} 

spring.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<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.xsd 
         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> 

    <aop:aspectj-autoproxy/> 

    <bean name="triangle" class="org.koushik.javabrains.model.Triangle"> 
     <property name="name" value="triangle"/> 
    </bean> 

    <bean name="circle" class="org.koushik.javabrains.model.Circle"> 
     <property name="name" value="circle"/> 
    </bean> 

    <bean name="shapeService" class="org.koushik.javabrains.service.ShapeService" autowire="byName"/> 

    <bean name="loggingAspect" class="org.koushik.javabrains.aspect.LoggingAspect"/> 

</beans> 

Ben Throug okudum h Öğretici sayfasındaki yorumlar ve farklı kavanozlarla denedim, ancak bunlardan hiçbiri işe yaramıyor. Her zaman aynı istisna ile sonuçlanırım.

+0

Eğer POM dosyasında 'aspectjweaver' bağımlılık var mı? – Reimeus

+0

Ben maven kullanmıyorum, ama evet classpath boyjweaver eksikti. – Felipe

cevap

14

Caused by: java.lang.NoClassDefFoundError: org/aspectj/weaver/tools/PointcutDesignatorHandler

Sen CLASSPATH'e için aspectjweaver.jar eklemelisiniz. Nasıl yapılmalı tam olarak IDE'nize bağlıdır.

+0

Teşekkürler, evet aspecjweaver.jar'ı classpaht'a eklemeyi tamamen unutmuşum. Şimdi koşuyor :) – Felipe

12

ise maven İhtiyacınız Bu veya herhangi bir sürümünü eklemek kullanarak:

<dependency> 
    <groupId>org.aspectj</groupId> 
    <artifactId>aspectjweaver</artifactId> 
    <version>1.8.6</version> 
</dependency>