当我练习时 Spring教程28 - 切入点和通配符表达式,我遇到以下问题:
Exception in thread"main"org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'triangle' defined in class path resource [springPointcuts.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut allGetters
您将在下面看到我的代码 我非常感谢你解决我的问题。
LoggingAspectPointcuts:
package org.koushik.javabrains.aspect;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class LoggingAspectPointcuts {
@Before("allGetters()")
public void LoggingAdvice(){
System.out.println("Advice run.Get Method called");
}
@Before("allGetters()")
public void secondAdvice() {
System.out.println("Second Advice executed ");
}
@Pointcut("execution(* get*())")
public void allGetters(){}
}
AopMainWildCardPointcuts:
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.koushik.javabrains.service.ShapeService;
public class AopMainWildCardPointcuts {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("springPointcuts.xml");
ShapeService shapeService= (ShapeService) ctx.getBean("shapeService");
System.out.println(shapeService.getCircle().getName());
}
springPointcuts.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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<aop:aspectj-autoproxy/>
<bean name="triangle" class="org.koushik.javabrains.model.Triangle">
<property name="name" value="Triangle Name"/>
</bean>
<bean name="circle" class="org.koushik.javabrains.model.Circle">
<property name="name" value="Circle Name"/>
</bean>
<bean name="loggingAspectPointcuts" class="org.koushik.javabrains.aspect.LoggingAspectPointcuts"/>
</beans>
答案 0 :(得分:1)
我猜你可能正在使用1.5版本的aspectjrt和aspectjweaver jars.use任何1.6版本你都会得到它wworkin
答案 1 :(得分:0)
替换....
<aop:aspectj-autoproxy/>
与......
<aop:aspectj-autoproxy>
<aop:include name="loggingAspectPointcuts"/>
</aop:aspectj-autoproxy>
答案 2 :(得分:0)
尝试使用正确版本的cglib.jar使用版本2.1_3或最新版本
asm-3.3.1
cglib-2.2.2
aspectjrt-1.6.11
aspectweaver-1.6.11.
确保使用上述罐子。