Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否可以使用SpringAOP或Aspectj为SpringRESTTemplate类和任何外部jar类编写AOP_Spring_Aspectj_Spring Aop_Aspectj Maven Plugin - Fatal编程技术网

是否可以使用SpringAOP或Aspectj为SpringRESTTemplate类和任何外部jar类编写AOP

是否可以使用SpringAOP或Aspectj为SpringRESTTemplate类和任何外部jar类编写AOP,spring,aspectj,spring-aop,aspectj-maven-plugin,Spring,Aspectj,Spring Aop,Aspectj Maven Plugin,可以使用SpringAOP或Aspectj为SpringRESTTemplate类编写AOP吗。例: @Around(“execution(*org.springframework.web.client.restemplate.getFor*(..)”) 谢谢我遇到了同样的问题,无法使AOP正常工作 然而,在这种情况下,有一个解决办法。由于restemplate扩展了InterceptingHttpAccessor,因此可以拦截通过restemplate对象发出的所有请求 记录所有HTTP请求

可以使用SpringAOP或Aspectj为SpringRESTTemplate类编写AOP吗。例:

@Around(“execution(*org.springframework.web.client.restemplate.getFor*(..)”)

谢谢

我遇到了同样的问题,无法使AOP正常工作

然而,在这种情况下,有一个解决办法。由于
restemplate
扩展了
InterceptingHttpAccessor
,因此可以拦截通过
restemplate
对象发出的所有请求

记录所有HTTP请求的示例配置:

@Bean
public RestTemplate restTemplate() {

    RestTemplate restTemplate = new RestTemplate();

    // (...)
    // setup code for the RestTemplate object

    restTemplate.getInterceptors().add((request, body, execution) -> {
        logger.info("HTTP {} request to {}", request.getMethod(), request.getURI());
        return execution.execute(request, body);
    });

    return restTemplate;
}

虽然这并不等同于使用aspect,但您可以通过拦截器和非常简单的配置获得类似的功能。

使用AspectJ绝对是可能的。请您提供任何链接以供参考。。。。您需要决定是否使用编译时编织还是加载时编织。如果可以,请使用编译时编织。有关编译时编织,请参阅。有关加载时编织,请参阅我已尝试过的加载时编织。我仍然无法为“org.springframework.web.client.restemplate.”类编写AOP。参考资料。