我想为我的@Entity 的方法定义一个@Around 切面
我所有的实体都在包 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();
}
}
但从来没有被拦截...我的错误在哪里?
在 spring 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..)")
但还是不行。
谢谢。
最佳答案
看起来你使用了spring-proxy-aop。仅当该类是 spring 托管 bean 并且建议的方法必须从其他对象调用时才有效。
尝试使用真正的aspectJ而不是spring-proxy-aop。
关于java - spring + aspectj,定义一个切面@Around,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4210507/