【发布时间】:2019-01-25 14:43:34
【问题描述】:
我有一个 aop 设置
@Target({ElementType.METHOD})
@Retention(value = RetentionPolicy.RUNTIME)
public @interface IgnoreHttpClientErrorExceptions { }
@Aspect
@Component
public class IgnoreHttpWebExceptionsAspect {
@Around(value = "@annotation(annotation)", argNames = "joinPoint, annotation")
public Object ignoreHttpClientErrorExceptions(ProceedingJoinPoint joinPoint, IgnoreHttpClientErrorExceptions annotation)
throws Throwable {
try {
//do something
} catch (HttpClientErrorException ex) {
//do something
}
}
如果我在服务层添加这个注解(@IgnoreHttpClientErrorExceptions),
@Service
public class SentenceServiceImpl implements SentenceService {
@Autowired
VerbClient verbClient;
@HystrixCommand(ignoreExceptions = {HttpClientErrorException.class})
@IgnoreHttpClientErrorExceptions
public ResponseEntity<String> patch(String accountId, String patch) {
return verbClient.patchPreferences(accountId, patch);
}
}
我的 AOP 被调用。
但是当我在我的伪装层中添加这个注释(@IgnoreHttpClientErrorExceptions)时。
@FeignClient(value = "account")
@RequestMapping(value = "/url")
public interface VerbClient {
@RequestMapping(value = "/{id}/preferences", method = RequestMethod.PATCH, consumes = MediaType.APPLICATION_JSON_VALUE)
@IgnoreHttpClientErrorExceptions
ResponseEntity<String> patchPreferences(@PathVariable("id") String accountId, String patchJson);
}
没有调用 AOP。
知道为什么当我在 feign-layer 中添加注释时没有调用 aop 吗?
添加的依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
【问题讨论】:
-
您可以尝试在您的@Configuration 类上添加@EnableAspectJAutoProxy 吗?
标签: spring aspectj spring-aop spring-cloud-feign