weixin_43308925
weixin_43308925
采纳率0%
2018-12-31 16:32 阅读 1.6k

学习Spring AOP的时候,只有加入<aop:config>到xml中,test就无法运行

学习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获得对象且正常运行..

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • qq_38670462 qq_38670462 2018-12-31 11:58

    大概是你的切面配置写反了,先写pointcut表达式再引用你写的point-ref,应该就好了

    点赞 评论 复制链接分享

相关推荐