我试图用Spring 3.1和无法配置切入点正确的切入点和建议的方法是运行基于@AspectJ的AOP:
切入点:
@Pointcut("execution(* point.*.*(..))")
public void selectAll() {}
意见后:
@After("selectAll()")
public void afterAdvice() {
System.out.println("profile has been setup.");
}
建议之前:
@Before("selectAll()")
public void beforeAdvice() {
System.out.println("Going to setup profile.");
}
&运行主程序,我得到异常:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'student' defined in class path resource [spring.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut selectAll
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
虽然当我让在beforeAdvice()和afterAdvice切入点表达式()方法,删除方法切入点每一件事工作细
@Before("execution(* point.*.*(..))")
public void beforeAdvice() {
System.out.println("Going to setup profile.");
}
@After("execution(* point.*.*(..))")
public void afterAdvice() {
System.out.println("profile has been setup.");
}
我试图申请切入点Student类的方法:
package point;
public class Student{
private Integer age;
private String name;
public void setAge(Integer age) {
this.age = age;
}
public Integer getAge() {
System.out.println("Age : " + age);
return age;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
System.out.println("Name : " + name);
return name;
}
public void printThrowException() {
System.out.println("Exception raised");
throw new IllegalArgumentException();
}
}
弹簧配置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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">
<aop:aspectj-autoproxy />
<bean id="student" class="point.Student">
<property name="name" value="Zara" />
<property name="age" value="11" />
</bean>
<bean id="logging" class="point.Logging" />
</beans>
Jar文件中:
aopalliance-1.0.jar
asm-3.3.1.jar
aspectj-1.7.1.jar
aspectjrt-1.6.8.jar
aspectjtools-1.5.4.jar
aspectjweaver-1.6.2.jar
cglib-2.2.2.jar
弹簧3.1罐子的