> For the complete documentation index, see [llms.txt](https://doc.shiker.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.shiker.tech/spring-he-xin-gong-neng/6.-spring-aop-api/6.6.-yi-bian-cheng-fang-shi-chuang-jian-aop-dai-li-proxyfactory.md).

# 6.6. 以编程方式创建 AOP 代理ProxyFactory

使用 Spring 以编程方式创建 AOP 代理很容易。这使您可以在不依赖 Spring IoC 的情况下使用 Spring AOP。

目标对象实现的接口被自动代理。以下清单显示了为目标对象创建代理，其中包含一个拦截器和一个Advisor：

```java
ProxyFactory factory = new ProxyFactory(myBusinessInterfaceImpl);
factory.addAdvice(myMethodInterceptor);
factory.addAdvisor(myAdvisor);
MyBusinessInterface tb = (MyBusinessInterface) factory.getProxy();
```

第一步是构造一个类型为 `org.springframework.aop.framework.ProxyFactory`的对象 。您可以像前面的示例一样使用目标对象创建它，或者指定要在备用构造函数中代理的接口。

您可以添加切面（使用拦截器作为一种特殊的建议）和/或切面程序，并在`ProxyFactory` 的生命周期中操纵它们。如果添加 `IntroductionInterceptionAroundAdvisor`，则可以使代理实现其他接口。

`ProxyFactory`(从`AdvisedSupport`继承 )还有一些方便的方法，可以让您添加其他切面类型，例如 before 和 throws 切面。 `AdvisedSupport`是`ProxyFactory` 和`ProxyFactoryBean` 的超类。

在大多数应用程序中，将 AOP 代理创建与 IoC 框架集成是最佳实践。我们切面您使用 AOP 从 Java 代码外部化配置，就像您通常应该做的那样。
