blo*_*low 5 java spring aspectj
我想为@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();
}
}
Run Code Online (Sandbox Code Playgroud)
但是从来没有被截获......我的错误在哪里?
在春天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>
Run Code Online (Sandbox Code Playgroud)
我也试试
@Around("target(data.entity.MyEntity)")
Run Code Online (Sandbox Code Playgroud)
和
@Around("target(data.entity..)")
Run Code Online (Sandbox Code Playgroud)
但仍然不行.
谢谢.
看起来你使用的是 spring-proxy-aop 。仅当该类是 spring manged bean,并且必须从其他对象调用建议的方法时,这才有效。
尝试使用真正的aspectJ而不是spring-proxy-aop。
| 归档时间: |
|
| 查看次数: |
2596 次 |
| 最近记录: |