spring + aspectj, определить аспект @Around

я хочу определить аспект @Around для метода моего @Entity

Все мои объекты находятся в пакете data.entity

Определите такой аспект:

@Aspect
public class TestAspect {

    @Around("execution(* data.entity..*(..))")
    public Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("INTERCEPT: "+pjp.toLongString());
        return pjp.proceed();
    }
}

Но никогда не перехватывается... где моя ошибка?

В весеннем 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:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <context:component-scan base-package="data.dao, data.service" />

    <tx:annotation-driven proxy-target-class="true"/>

    <aop:aspectj-autoproxy/>

    <bean id="testAspect" class="spring.TestAspect" />

    ... datasource and other ...

</beans>

я тоже пытаюсь

@Around("target(data.entity.MyEntity)")

а также

@Around("target(data.entity..)")

но все равно не работает.

Спасибо.


person blow    schedule 18.11.2010    source источник


Ответы (2)


Похоже, вы используете spring-proxy-aop. Это работает только в том случае, если класс является управляемым bean-компонентом spring, и рекомендуемый метод должен вызываться из другого объекта.

Попробуйте использовать реальный аспектJ вместо spring-proxy-aop.

person Ralph    schedule 18.11.2010

Я только начал использовать АОП, и ниже приведены результаты моего уровня.

  1. Я предполагаю, что у вас есть необходимые файлы jar, aspectjweaver-1.6.10.jar и org.springframework.aop-3.0.5.RELEASE.jar, присутствующие в вашем пути к классам приложений.

  2. Метод aroundAdvice, как вы определили в настоящее время, идеален.

  3. Не могли бы вы удалить строку ниже и попробовать.

    ‹context:component-scan base-package="data.dao, data.service" /›

person Darshan    schedule 26.02.2011