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
请问大神这是为什么啊?我直接下的老师的代码,然后参照写出对应的语句,为什么会报错呢
我也遇到这个问题了,原因是,使用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>
遇到相同的问题,导入楼上说的那三个包就可以的,在这个网站去找:http://www.java2s.com/Code/Jar/CatalogJar.htm
你看看你是不是少了这三个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>
你刚好把第一张图的配置信息没有截取全。没有截取到的地方就是你错的地方