1.14. 注册LoadTimeWeaver

    预计阅读时间: 小于 1 分钟
    The `LoadTimeWeaver` is used by Spring to dynamically transform classes as they are loaded into the Java virtual machine (JVM). Spring 使用 `LoadTimeWeaver` 在类被加载到 Java 虚拟机(JVM)时动态转换类。 To enable load-time weaving, you can add the `@EnableLoadTimeWeaving` to one of your `@Configuration` classes, as the following example shows: 要启用加载时织入,你可以将 `@EnableLoadTimeWeaving` 添加到你的 `@Configuration` 类之一中,如下例所示: ```

    @Configuration @EnableLoadTimeWeaving public class AppConfig { }

    ``` @Configuration @EnableLoadTimeWeaving class AppConfig
    Alternatively, for XML configuration, you can use the `context:load-time-weaver` element: 或者,对于 XML 配置,你可以使用 `context:load-time-weaver` 元素:
    <beans>
        <context:load-time-weaver/>
    </beans>
    
    Once configured for the `ApplicationContext`, any bean within that `ApplicationContext` may implement `LoadTimeWeaverAware`, thereby receiving a reference to the load-time weaver instance. This is particularly useful in combination with [Spring’s JPA support](https://docs.spring.io/spring-framework/docs/5.3.39/reference/html/data-access.html#orm-jpa) where load-time weaving may be necessary for JPA class transformation. Consult the [ `LocalContainerEntityManagerFactoryBean`](https://docs.spring.io/spring-framework/docs/5.3.39/javadoc-api/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.html) javadoc for more detail. For more on AspectJ load-time weaving, see [Load-time Weaving with AspectJ in the Spring Framework](#aop-aj-ltw). 一旦为 `ApplicationContext` 配置,该 `ApplicationContext` 内的任何 bean 都可以实现 `LoadTimeWeaverAware` ,从而获得对加载时编织实例的引用。这在与 Spring 的 JPA 支持结合使用时特别有用,因为 JPA 类转换可能需要加载时编织。有关更多详细信息,请参阅 `LocalContainerEntityManagerFactoryBean` javadoc。有关 AspectJ 加载时编织的更多信息,请参阅 Spring 框架中的“AspectJ 加载时编织”。