上一节 1.13. Environment Abstraction
下一节 1.15. Additional Capabilities of the ApplicationContext
1.14. Registering a LoadTimeWeaver
1.1.4. 注册一个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:
要启用load-time weaving,可以将@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,从而接收到
load-time weaver 实例的引用。
这在与Spring的JPA支持相结合时特别有用,其中 load-time weaving
对于JPA类转换可能是必要的。
更多细节请参考LocalContainerEntityManagerFactoryBean 的 javadoc。
有关AspectJ装入时编织的更多信息,请参见章节
Load-time Weaving with AspectJ in the Spring Framework 。