我想监视传出请求的时间以跟踪我的应用程序中的HTTP集成。常见的代码路径,个个是HttpClient.execute
,这样似乎对AOP的自然目标:Apache HttpClient.exe的Spring AOP监视执行
@Around("execution(* org.apache.http.client.HttpClient.execute(..)) && args(httpUriRequest)")
public Object timeApacheRequest(ProceedingJoinPoint proceedingJoinPoint, HttpUriRequest httpUriRequest) throws Throwable {
// etc.
}
然而,当我用我的代理,互动春HttpComponentsClientHttpRequestFactory
代码吹起来这是instanceof
检查代理在传递
Caused by: java.lang.IllegalArgumentException: 'httpClient' is not of type CloseableHttpClient Object of class [com.sun.proxy.$Proxy22] must be an instance of class org.apache.http.impl.client.CloseableHttpClient
手术检查中HttpComponentsClientHttpRequestFactory
:
public HttpComponentsClientHttpRequestFactory(HttpClient httpClient) {
Assert.notNull(httpClient, "'httpClient' must not be null");
Assert.isInstanceOf(CloseableHttpClient.class, httpClient, "'httpClient' is not of type CloseableHttpClient");
this.httpClient = (CloseableHttpClient) httpClient;
}
有我为const更好的办法ruct我的代理,将消除这个问题?
为了澄清,目前我在声明bean的配置类上使用@EnableAspectJAutoProxy
批注建立当前代理。
你怎么声明代理? - 澄清 - aspectj:autoproxy或类似的东西? –
@DaveG,您的评论独自向我发送了正确的方向 - 它让我发现了注释的“proxyTargetClass”属性,这看起来正是我所需要的。我想知道你能否更好地解释它的用法是正确的还是不正确的? – jwilner