spring + aspectj, определить аспект @Around - PullRequest
5 голосов
/ 18 ноября 2010

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

Все мои сущности находятся в пакете data.entity

A, определить аспект следующим образом:

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

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

Спасибо.

Ответы [ 2 ]

3 голосов
/ 18 ноября 2010

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

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

0 голосов
/ 26 февраля 2011

Я только начал использовать AOP, и ниже приведены результаты на моем уровне

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

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

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

...