我有以下beans.xml
<!-- Aspect -->
<bean id="bar" class="biz.tugay.spashe.aspect.BarImpl"/>
<aop:config>
<aop:aspect ref="bar">
<aop:before method="bar"
pointcut="target(biz.tugay.spashe.Foo))"/>
</aop:aspect>
</aop:config>
<!-- Business Logic -->
<bean id="foo" class="biz.tugay.spashe.FooImpl"/>
正如你所看到我不使用元素:
<aop:aspectj-autoproxy/>
用于根据官方documentation在Spring Framework中启用AspectJ支持。
我所拥有的方面,BarImpl
是一个POJO:
public class BarImpl {
public void bar() throws Throwable {
System.out.println("Before..");
}
}
我希望这个项目能够编译并运行得很好。但是,在运行时我得到了异常:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#5c7b24c2': Cannot create inner bean '(inner bean)#24ee8489' of type [org.springframework.aop.aspectj.AspectJExpressionPointcut] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#24ee8489': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.AspectJExpressionPointcut]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
只有在我添加依赖项
时才会修复<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.8.12</version>
</dependency>
到我的项目。
为什么在这种情况下我需要 aspectjtools 依赖关系?如何在没有AspectJ支持的情况下为面向方面编程配置Spring Framework?