学习Spring AOP的时候,只有加入aop:config到xml中,test就无法运行
菜鸟入门,多多指教。
Xml配置aop的时候可以自动联想出来,不会报错
抛出异常如下
十二月 31, 2018 4:12:16 下午 org.springframework.context.support.AbstractApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot create inner bean '(inner bean)#365185bd' of type [org.springframework.aop.aspectj.AspectJMethodBeforeAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#365185bd': Resolution of declared constructors on bean Class [org.springframework.aop.aspectj.AspectJMethodBeforeAdvice] from ClassLoader [sun.misc.Launcher$AppClassLoader@4aa298b7] failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/JoinPoint
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"
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-4.0.xsd"
>
<bean id="aspectBiz" class="baseClass.AspectBiz" scope="prototype"></bean>
<bean id="aspect" class="baseClass.Aspect" scope="prototype"></bean>
<!-- 切面配置 -->
<aop:config>
<aop:aspect id="aopAspect" ref="aspect">
<aop:before method="before" pointcut-ref="bizPointCut"/>
<aop:pointcut expression="execution(* baseClass.*Biz *(..))" id="bizPointCut"/>
</aop:aspect>
</aop:config>
</beans>
如果注释掉切面配置的话就能通过getBeans获得对象且正常运行..