# 5.4.5. 切面说明

切面说明（在 AspectJ 中称为类型间声明）使切面能够声明通知对象实现给定接口，并代表这些对象提供该接口的实现。

您可以使用`@DeclareParents`注解进行介绍。此注解用于声明匹配类型有一个新的父级（因此得名）。例如，给定一个名为`UsageTracked` 的接口和一个名为`DefaultUsageTracked` 的接口的实现， 以下切面声明服务接口的所有实现者也实现`UsageTracked`接口（例如，通过 JMX 进行统计）：

```java
@Aspect
public class UsageTracking {

    @DeclareParents(value="com.xzy.myapp.service.*+", defaultImpl=DefaultUsageTracked.class)
    public static UsageTracked mixin;

    @Before("com.xyz.myapp.CommonPointcuts.businessService() && this(usageTracked)")
    public void recordUsage(UsageTracked usageTracked) {
        usageTracked.incrementUseCount();
    }

}
```

要实现的接口由注解字段的类型决定。注解`@DeclareParents`的 `value`属性是 AspectJ 类型模式。任何匹配类型的 bean 都会实现`UsageTracked`接口。请注意，在前面示例的之前通知中，服务 bean 可以直接用作`UsageTracked`接口的实现。如果以编程方式访问 bean，您将编写以下内容：

```java
UsageTracked usageTracked = (UsageTracked) context.getBean("myService");
```


---

# Agent Instructions: 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:

```
GET https://doc.shiker.tech/spring-he-xin-gong-neng/5.-spring-mian-xiang-qie-mian-bian-cheng/5.4.-aspectj-zhi-chi/5.4.5.-qie-mian-shuo-ming.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
