【发布时间】:2017-03-13 11:25:13
【问题描述】:
我已经创建了一个像
这样的 AspectJ 拦截器@Aspect
public class RequestSpecificServiceAspect {
@Pointcut("execution( * com.mycompany.c.d.doesTreatmentEqualsAndTrigger(..))")
private void callInterceptor(){}
@Before("callInterceptor()")
public void getCallStack(){
StackTraceElement[] callingStack = Thread.currentThread().getStackTrace();
PopulateServiceDependentMap populateServiceDependentMap = new PopulateServiceDependentMap();
populateServiceDependentMap.populateMap(callingStack, "ServiceName");
}
}
这工作得很好,因为这是一个试用代码,我现在用我想要的实际拦截器替换它,就像这样
@Pointcut("execution( * mycompany.f.g.findPluginForRequest(..)) && args(request)")
private void actualInterceptor(BSFBatchRequest request){}
@Before("actualInterceptor(request)")
public void getBSFCall(BSFBatchRequest request){
StackTraceElement[] callingStack = Thread.currentThread().getStackTrace();
PopulateServiceDependentMap populateServiceDependentMap = new PopulateServiceDependentMap();
populateServiceDependentMap.populateMap(callingStack, request);
}
但现在我的拦截器没有拦截对findPluginForRequest() 函数的调用。
为什么会发生这种情况,我该如何解决?
这是我的 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: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.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"
default-autowire="no">
<context:annotation-config/>
<aop:aspectj-autoproxy/>
<bean name="com.dpx.dependencyGraphFactory" class="com.mycompany.dpx.dependencytree.ModuleToModuleDependencyGraphFactory"></bean>
<bean name="com.dpx.serviceInterceptor" class="com.mycompany.dpx.dependencytree.RequestSpecificServiceAspect"/>
</beans>
findPluginForRequest() 的签名是 private AllPurposeCache<BSFBatchRequest, BSFReply> findPluginForRequest(final BSFBatchRequest request)。我尝试将切入点更改为
@Pointcut("execution(private * mycompany.f.g.findPluginForRequest(..)) && args(request)")
private void actualInterceptor(BSFBatchRequest request){}
但还是不行。
【问题讨论】:
-
我需要更多信息。请显示
findPluginForRequest的包名称和签名,并告诉我是否在不删除args()部分和切入点/建议参数的情况下工作。另一个问题:在第一个示例中,您调用populateMap,第二个参数是一个字符串,现在它是一个请求对象。这是为什么呢? -
包名我不能告诉你保密协议的原因,但我可以告诉你它是一个普通的包。即使没有
args()部分,它也不起作用。为了回答第二个问题,我调用了一个请求对象,因为这个请求对象有一个方法可以返回一个字符串和一些我需要的更多数据。早些时候,因为这是一个试验,我只是硬编码该数据并传递字符串以检查它是否工作。 -
您需要帮助,但不愿意分享足够的信息。我要了
findPluginForRequest的签名。除非我至少看到了全貌的重要部分,否则这是一个让人们猜测的问答节目,而不是一个可以通过推理来回答的有意义的问题。 -
findPluginForRequest的签名是private AllPurposeCache<BSFBatchRequest, BSFReply> findPluginForRequest(final BSFBatchRequest request)。与此关系不大,但 AspectJ 拦截器会导致超时吗?
标签: java aop aspectj spring-aop interceptor