问答详情
源自:5-4 Advice应用(上)

为什么会错呢

586a05b50001d1e405000232.jpg

586a05be0001c06405000231.jpg

586a05bf0001163505000322.jpg

586a05c00001451405000246.jpg

586a05c100014adf05000188.jpg

Error creating bean with name 'moocAspect' defined in class path resource [spring-aop-schema-advice.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot create inner bean '(inner bean)#412b7140' 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)#412b7140': Cannot resolve reference to bean 'moocPointcut' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'moocPointcut' is defined

请问大神这是为什么啊?我直接下的老师的代码,然后参照写出对应的语句,为什么会报错呢

提问者:慕粉1474367326 2017-01-02 15:50

个回答

  • 阳光洒在路上就不怕心碎f
    2017-03-08 20:43:27
    已采纳

    我也遇到这个问题了,原因是,使用aop还要添加三个jar包: aopalliance  aspectjrt  aspectjweaver,在pom中添加如下代码即可,上面的回复中有个包的半杯有问题,使用不了,我的这个亲测可以。
      

                    <dependency>
    			<groupId>aopalliance</groupId>
    			<artifactId>aopalliance</artifactId>
    			<version>1.0</version>
    		</dependency>
    
    		<dependency>
    			<groupId>org.aspectj</groupId>
    			<artifactId>aspectjrt</artifactId>
    			<version>1.8.10</version>
    		</dependency>
    
    		<dependency>
    			<groupId>org.aspectj</groupId>
    			<artifactId>aspectjweaver</artifactId>
    			<version>1.8.9</version>
    		</dependency>


  • happyflyer
    2017-10-15 17:59:34

    遇到相同的问题,导入楼上说的那三个包就可以的,在这个网站去找:http://www.java2s.com/Code/Jar/CatalogJar.htm

  • 如遇明主
    2017-01-08 16:53:58

    你看看你是不是少了这三个jar包,下面是maven配置,如果没用maven ,可以下载三个jar包导入进去

    <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-aop</artifactId>

    <version>${spring.version}</version>

    </dependency>

    <dependency>

    <groupId>org.aspectj</groupId>

    <artifactId>aspectjrt</artifactId>

    <version>${aspectj.version}</version><!--版本号我用的是1.8.0-->

    </dependency>

    <dependency>

    <groupId>org.aspectj</groupId>

    <artifactId>aspectjweaver</artifactId>

    <version>1.6.0</version>

    </dependency>


  • LiuKeqing
    2017-01-04 22:17:49

    你刚好把第一张图的配置信息没有截取全。没有截取到的地方就是你错的地方