---
title: "AOP代理"
author: "chy0919"
date: "2021-10-09T14:31:31Z"
tags: ["动态代理"]
categories: ["编程语言"]
slug: "aop"
draft: false
lastmod: "2021-10-09T14:31:31Z"
id: 2521154
url: "https://chy0919.iteye.com/blog/2521154"
---

今天在使用事务注解@Transactional 对线程池添加事务时，需要通过动态代理来调用对应的方法，调用中报错信息如下：

java.lang.IllegalStateException: Cannot find current proxy: Set 'exposeProxy' property on Advised to 'true' to make it available.

at org.springframework.aop.framework.AopContext.currentProxy(AopContext.java:64)

 

问题原因：生成代理类时使用的是AopContext.currentProxy()方法，但未进行配置。

解决方式：在类上添加如下注解

```
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
```