註冊 LoadTimeWeaver

LoadTimeWeaver 由 Spring 用於在類別載入到 Java 虛擬機器 (JVM) 時動態轉換它們。

若要啟用載入時織入,您可以將 @EnableLoadTimeWeaving 新增到您的 @Configuration 類別之一,如下列範例所示

  • Java

  • Kotlin

@Configuration
@EnableLoadTimeWeaving
public class AppConfig {
}
@Configuration
@EnableLoadTimeWeaving
class AppConfig

或者,對於 XML 組態,您可以使用 context:load-time-weaver 元素

<beans>
	<context:load-time-weaver/>
</beans>

一旦為 ApplicationContext 組態完成,該 ApplicationContext 內的任何 Bean 都可以實作 LoadTimeWeaverAware,從而接收對載入時織入器實例的參考。這與 Spring 的 JPA 支援 結合使用特別有用,在這種情況下,載入時織入對於 JPA 類別轉換可能是必要的。有關更多詳細資訊,請參閱 LocalContainerEntityManagerFactoryBean javadoc。有關 AspectJ 載入時織入的更多資訊,請參閱 Spring Framework 中使用 AspectJ 的載入時織入