基于Spring 3.1的基于@AspectJ的AOP [英] @AspectJ Based AOP with Spring 3.1

查看:131
本文介绍了基于Spring 3.1的基于@AspectJ的AOP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Spring 3.1&中运行基于@AspectJ的AOP.无法正确配置切入点 切入点和建议方法是:

I am trying to run a @AspectJ Based AOP with Spring 3.1 & not able to configure pointcut properly Pointcut and advice methods are :

切入点:

@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.");
}

&运行主程序我出现异常:

& run main program i got Exception:

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()方法中给出切入点表达式时,请删除PointCuts方法,使其一切正常

although when i give pointcut expression in beforeAdvice() and afterAdvice() methods , remove PointCuts method every thing work fine

@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类的方法:

i am trying to apply pointcut to method of Student class:

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();
}
 }

spring配置xml:

spring configuration 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

带有Spring 3.1罐子的

with spring 3.1 jar's

推荐答案

解决了问题:创建bean时出现的问题是由于旧的jars

已替换的罐子

 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

aopalliance-1.0.jar
asm-3.3.1.jar
aspectj-1.7.1.jar
aspectjrt-1.7.0.jar
aspectjweaver-1.7.0.jar
cglib-2.2.2.jar

这篇关于基于Spring 3.1的基于@AspectJ的AOP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆