Java 添加简单的Before通知时的Spring AOP BeanCreationException

Java 添加简单的Before通知时的Spring AOP BeanCreationException,java,spring,aop,Java,Spring,Aop,我是春天AOP的新手。在建议之前,我用一个简单的@编写了一个方面,如下所示 package testing_spring; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; @Aspect public class MyTestAspect { @Before("execution(public void open())") public void runThi

我是春天AOP的新手。在建议之前,我用一个简单的
@编写了一个方面,如下所示

package testing_spring;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class MyTestAspect {

  @Before("execution(public void open())")
  public void runThis() {
    System.out.println("About to open something ...");
  }
}
这是context.xml文件:

<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"
  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 ">

  <aop:aspectj-autoproxy />

  <bean class="testing_spring.House" name="house">
    <property name="windows">
      <list>
        <ref bean="window1"/>
        <ref bean="window2"/>
        <ref bean="window3"/>
      </list>
    </property>
    <property name="doors">
      <list>
        <ref bean="door"/>
      </list>
    </property>
  </bean>

  <bean class="testing_spring.Window" name="window1" id="window1"/>
  <bean class="testing_spring.Window" name="window2" id="window2"/>
  <bean class="testing_spring.Window" name="window3" id="window3"/>

  <bean class="testing_spring.Door" name="door" id="door"/>


  <bean class="testing_spring.MyTestAspect" name="mta"/>
</beans>
但是当我在注释之前注释掉
@时,一切正常,它打印:

My house has 1 doors and 3 windows.

所以before的建议肯定有问题,但我不明白它是什么。

您可能没有为aspectj weaver.jar添加类路径。

您的建议没有问题。您只是没有应用AOP所需的依赖项。这就是
java.lang.NoClassDefFoundError
告诉您的。谢谢,您完全正确!
cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'house' defined in class path resource [context.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
My house has 1 doors and 3 windows.