weixin_43308925 2018-12-31 16:32 采纳率: 0%
浏览 1736

学习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 2018-12-31 11:58
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体