Registering a LoadTimeWeaver

1.14. Registering a LoadTimeWeaver

The LoadTimeWeaver is used by Spring to dynamically transform classes as they are loaded into the Java virtual machine (JVM).

当类加载到Java虚拟机(JVM)中时,Spring使用LoadTimeWeaver动态地转换类。

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 {
}

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 where load-time weaving may be necessary for JPA class transformation. Consult the LocalContainerEntityManagerFactoryBean javadoc for more detail. For more on AspectJ load-time weaving, see Load-time Weaving with AspectJ in the Spring Framework.

一旦为ApplicationContext配置好,该ApplicationContext中的任何bean都可以实现LoadTimeWeaverAware,从而接收到加载时编织器实例的引用。这在与Spring的JPA支持结合时特别有用,因为在Spring的JPA类转换中可能需要加载时编织。更多细节请参考LocalContainerEntityManagerFactoryBean javadoc。有关AspectJ加载时编织的更多信息,请参见Spring框架中使用AspectJ的加载时编织。
posted @ 2022-09-13 16:19  丶Jan  阅读(44)  评论(0)    收藏  举报