> For the complete documentation index, see [llms.txt](https://docs.flydean.com/spring-framework-documentation5/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flydean.com/spring-framework-documentation5/core-technologies/6.spring-aop-apis/6.6create-aop-with-proxyfactory.md).

# 6.6使用ProxyFactory创建AOP代理

用Spring编程创建AOP代理很容易。这允许你使用SpringAOP而不依赖SpringIOC。

由目标对象实现的接口被自动代理。下面的列表显示使用一个拦截器和一个顾问为目标对象创建代理：

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

第一步是构造org.springframework.aop.framework.proxyFactory类型的对象。你可以使用目标对象创建此对象，如前面的示例所示，或者指定要在备用构造函数中代理的接口。

你可以添加建议（拦截器作为一种专门的建议）、顾问，或者两者兼而有之，并在代理工厂的生命周期中操纵它们。如果添加一个IntroductionInterceptionAroundAdvisor，则可以使代理实现其他接口。

ProxyFactory（继承自AdvisedSupport）上还有一些方便方法，允许你添加其他通知类型，如before和throw advice。AdvisedSupport是ProxyFactory和ProxyFactoryBean的超类。

> 在大多数应用程序中，将AOP代理创建与IOC框架集成是最佳实践。我们建议你一般用AOP将Java代码的配置外部化。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.flydean.com/spring-framework-documentation5/core-technologies/6.spring-aop-apis/6.6create-aop-with-proxyfactory.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
