烈焰星辰 2023-01-30 17:29 采纳率: 100%
浏览 51
已结题

java spring aop

问题遇到的现象和发生背景

spring使用aop 进行简单的应用

遇到的现象和发生背景,请写出第一个错误信息

Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.AspectJPointcutAdvisor]:

用代码块功能插入代码,请勿粘贴截图。 不用代码块回答率下降 50%

application.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:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd">

<context:component-scan base-package="ll"/>
    <bean id="seq"  class="ll.service.impl.SeImpl"/>
    
    <bean id="pointCut"  class="ll.aop.PointCut"/>
    
    <aop:config>

        
        <aop:aspect ref="pointCut">
            
            <aop:pointcut id="point" expression="execution(* com.ll.service.impl.SeImpl.*(..))"/>
            
            <aop:before method="before" pointcut-ref="point"/>
            <aop:after method="after" pointcut-ref="point"/>
        </aop:aspect>

    </aop:config>
    
    <aop:aspectj-autoproxy/>
</beans>

接口定义
```java
public interface Se {
    public void tt();
}

实现类

public class SeImpl implements Se {
    @Override
    public void tt() {
        System.out.println("aaa+bbbb");
    }
}


切面类

//切面类
public class PointCut {
    //前置通知
    public void before(){
        System.out.println("aaaa");
    }
    //后置通知
    public void after(){
        System.out.println("bbb");
    }
}

测试类

 @Test
    public void test(){
        ApplicationContext context = new ClassPathXmlApplicationContext("application.xml");

        Se se1 =(SeImpl) context.getBean("seq");
        se1.tt();

    }

运行结果及详细报错内容

报错就是出现上面的内容:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Bean instantiation

我的解答思路和尝试过的方法,不写自己思路的,回答率下降 60%

我一开始以为是aspectjweaver 的版本不对 换了1.9几的 1.7.2 1.6.12 1.6.11 等都不行
后来仔细看个下面部分的代码 ,没有发现有啥问题 我看最后的报错是这个对象没有加到spring容器中 导致获取这个对象的时候没有找到


 <aop:pointcut id="point" expression="execution(* com.ll.service.impl.SeImpl.*(..))"/>

我想要达到的结果,如果你需要快速回答,请尝试 “付费悬赏”

可以帮我看看这个是哪的问题吗希望可以解决这个错误,弄了一天也没有解决

  • 写回答

4条回答 默认 最新

  • zcl_1991 2023-01-31 09:20
    关注

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 2月8日
  • 已采纳回答 1月31日
  • 创建了问题 1月30日

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败