烈焰星辰 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • m0_54204465 2023-01-30 17:35
    关注

    这个错误是说,Spring在创建'org.springframework.aop.aspectj.AspectJPointcut'的bean的时候发生了异常。有两个可能的原因:
    1.AspectJPointcut类的定义不正确,请检查是否有语法错误
    2.AspectJPointcut类的包名未在Spring配置文件component-scan标签中扫描,请确认是否包含这个包。

    评论
  • CSDN-Ada助手 CSDN-AI 官方账号 2023-01-30 20:53
    关注
    评论
  • 君易大大 2023-01-31 10:22
    关注

    你这个报错应该是没有扫描到包吧,把扫描配置改成com.ll试一下

    
    <context:component-scan base-package="com.ll" />
    
    
    评论
查看更多回答(3条)

报告相同问题?

问题事件

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

悬赏问题

  • ¥30 android百度地图SDK海量点显示标题
  • ¥15 windows导入environment.yml运行conda env create -f environment_win.yml命令报错
  • ¥15 这段代码可以正常运行,打包后无法执行,在执行for内容之前一直不断弹窗,请修改调整
  • ¥15 C语言判断有向图是否存在环路
  • ¥15 请问4.11到4.18以及4.27和4.29公式的具体推导过程是怎样的呢
  • ¥20 将resnet50中的卷积替换微ODConv动态卷积
  • ¥15 通过文本框输入商品信息点击按钮将商品信息列举出来点击加入购物车商品信息添加到表单中
  • ¥100 这是什么压缩算法?如何解压?
  • ¥20 upload上传实验报错500,如何解决?(操作系统-windows)
  • ¥15 谁知道 ShaderGraph 那个节点可以接入 Particle System -> Custom Data