Java 弹簧&x2B;aspectj,在周围定义一个方面
我想为@Entity的方法定义一个@Around方面 我的所有实体都在包data.entity中 A定义如下方面:Java 弹簧&x2B;aspectj,在周围定义一个方面,java,spring,aspectj,Java,Spring,Aspectj,我想为@Entity的方法定义一个@Around方面 我的所有实体都在包data.entity中 A定义如下方面: @Aspect public class TestAspect { @Around("execution(* data.entity..*(..))") public Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable { System.out.println("INTERCE
@Aspect
public class TestAspect {
@Around("execution(* data.entity..*(..))")
public Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("INTERCEPT: "+pjp.toLongString());
return pjp.proceed();
}
}
但永远不会被拦截。。。我的错误在哪里
在SpringXML中,我有以下内容:
<?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>
及
但仍然不起作用
谢谢。看起来您使用的是spring代理aop。只有当类是spring管理的bean,并且adviced方法必须从其他对象调用时,这才有效
尝试使用RealAspectJ而不是spring代理aop。我刚刚开始使用aop,下面是我级别的发现
@Around("target(data.entity.MyEntity)")
@Around("target(data.entity..)")